Ok, so I've got my Android application and it wont boot with a "unable to instantiate activity ComponentInfo{}" error, basically theres something wrong in my manifest file that won't let the application launch the first activity. I made a new but essentially duplicated project (manually copying across the Java+XML code for Main, second + third 'tester' activities, and of course Strings). I left the manifest of the new project as it is but added the activity lines for the tester. I wanted everything as stock basically so nothing could go wrong, and nothing did, the application loaded on emulator and my phone alright.
So I copy the new manifest to my old project in an effort to 'default' it, and I copy and pasted the tester activity code that was already there and worked, for the other 3 activity's. Suddenly it doesn't want to work. Everything is there, but what's the problem? (note the icon drawable is changed but that's nothing to do with it). All the activity names match up to package names and whatnot. Could this be a bug? I honestly cannot find anything wrong.
Duplicate (+ working) code
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/logo3"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.ollygrov.bakerspride.Main"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ollygrov.bakerspride.Cal"
android:label="#string/title_activity_cal" >
</activity>
<activity
android:name="com.ollygrov.bakerspride.Breads"
android:label="#string/title_activity_breads" >
</activity>
</application>
Old (+ not working) code
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.ollygrov.bakerspride.Main"
android:label="#string/app_title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ollygrov.bakerspride.Cal"
android:label="#string/title_activity_cal" >
</activity>
<activity
android:name="com.ollygrov.bakerspride.Breads"
android:label="#string/title_activity_breads" >
</activity>
<activity
android:name="com.ollygrov.bakerspride.Gal"
android:label="#string/title_activity_gal" >
</activity>
<activity
android:name="com.ollygrov.bakerspride.Tut"
android:label="#string/title_activity_tut" >
</activity>
<activity
android:name="com.ollygrov.bakerspride.Rec"
android:label="#string/title_activity_rec" >
</activity>
</application>
EDIT: I just copied and pasted the codes into the search bar on Chrome (changing the droid:icon and droid:label to fit) and they are exactly the same!! What?! Am I not allowed to have 6 activities or something?
Errors:
09-04 11:33:04.895: E/AndroidRuntime(717): FATAL EXCEPTION: main
09-04 11:33:04.895: E/AndroidRuntime(717): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ollygrov.bakerspride/com.ollygrov.bakerspride.Main}: java.lang.NullPointerException
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.os.Looper.loop(Looper.java:137)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-04 11:33:04.895: E/AndroidRuntime(717): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 11:33:04.895: E/AndroidRuntime(717): at java.lang.reflect.Method.invoke(Method.java:511)
09-04 11:33:04.895: E/AndroidRuntime(717): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-04 11:33:04.895: E/AndroidRuntime(717): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-04 11:33:04.895: E/AndroidRuntime(717): at dalvik.system.NativeStart.main(Native Method)
09-04 11:33:04.895: E/AndroidRuntime(717): Caused by: java.lang.NullPointerException
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.Activity.findViewById(Activity.java:1825)
09-04 11:33:04.895: E/AndroidRuntime(717): at com.ollygrov.bakerspride.Main.<init>(Main.java:19)
09-04 11:33:04.895: E/AndroidRuntime(717): at java.lang.Class.newInstanceImpl(Native Method)
09-04 11:33:04.895: E/AndroidRuntime(717): at java.lang.Class.newInstance(Class.java:1319)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
09-04 11:33:04.895: E/AndroidRuntime(717): ... 11 more
09-04 11:34:58.665: E/Trace(765): error opening trace file: No such file or directory (2)
09-04 11:34:59.095: D/AndroidRuntime(765): Shutting down VM
09-04 11:34:59.095: W/dalvikvm(765): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
09-04 11:34:59.114: E/AndroidRuntime(765): FATAL EXCEPTION: main
09-04 11:34:59.114: E/AndroidRuntime(765): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ollygrov.bakerspride/com.ollygrov.bakerspride.Main}: java.lang.NullPointerException
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.ActivityThread.access$600(ActivityThread.java:130)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.os.Looper.loop(Looper.java:137)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.ActivityThread.main(ActivityThread.java:4745)
09-04 11:34:59.114: E/AndroidRuntime(765): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 11:34:59.114: E/AndroidRuntime(765): at java.lang.reflect.Method.invoke(Method.java:511)
09-04 11:34:59.114: E/AndroidRuntime(765): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
09-04 11:34:59.114: E/AndroidRuntime(765): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-04 11:34:59.114: E/AndroidRuntime(765): at dalvik.system.NativeStart.main(Native Method)
09-04 11:34:59.114: E/AndroidRuntime(765): Caused by: java.lang.NullPointerException
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.Activity.findViewById(Activity.java:1825)
09-04 11:34:59.114: E/AndroidRuntime(765): at com.ollygrov.bakerspride.Main.<init>(Main.java:19)
09-04 11:34:59.114: E/AndroidRuntime(765): at java.lang.Class.newInstanceImpl(Native Method)
09-04 11:34:59.114: E/AndroidRuntime(765): at java.lang.Class.newInstance(Class.java:1319)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
09-04 11:34:59.114: E/AndroidRuntime(765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
The problem is your Main Constructor:
09-04 11:33:04.895: E/AndroidRuntime(717): Caused by: java.lang.NullPointerException
09-04 11:33:04.895: E/AndroidRuntime(717): at android.app.Activity.findViewById(Activity.java:1825)
09-04 11:33:04.895: E/AndroidRuntime(717): at com.ollygrov.bakerspride.Main.<init>(Main.java:19)
In line 19 of Main.java you are trying to call findViewById() which will obviously not work. It is way to early to call such code in the constructor.
My best guess is, that you need to move EVERYTHING from the cronstructor to onCreate() of the Activity.
Normally you don't need a custom constructor in Activities or Fragments.
Related
My Android code using Google Map API v2 is not working on genymotion. I have developed this code and run on my PC and it works fine, but the same code I am trying in my laptop then it gives me error "app has unfortunately stopped". I checked my code 100 times and it's perfect, everything is perfect in configuration at Google API console.
I have installed Google Play service in genymotion using following links:
http://filetrip.net/dl?4SUOrdcMRv
http://wiki.cyanogenmod.org/w/Google_Apps#gappsCM11
Logcat output:
09-04 20:07:15.691: E/AndroidRuntime(2728): FATAL EXCEPTION: main
09-04 20:07:15.691: E/AndroidRuntime(2728): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.geolocation/com.example.geolocation.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.geolocation.MainActivity" on path: /data/app/com.example.geolocation-2.apk
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.os.Handler.dispatchMessage(Handler.java:99)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.os.Looper.loop(Looper.java:137)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-04 20:07:15.691: E/AndroidRuntime(2728): at java.lang.reflect.Method.invokeNative(Native Method)
09-04 20:07:15.691: E/AndroidRuntime(2728): at java.lang.reflect.Method.invoke(Method.java:511)
09-04 20:07:15.691: E/AndroidRuntime(2728): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-04 20:07:15.691: E/AndroidRuntime(2728): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-04 20:07:15.691: E/AndroidRuntime(2728): at dalvik.system.NativeStart.main(Native Method)
09-04 20:07:15.691: E/AndroidRuntime(2728): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.geolocation.MainActivity" on path: /data/app/com.example.geolocation-2.apk
09-04 20:07:15.691: E/AndroidRuntime(2728): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
09-04 20:07:15.691: E/AndroidRuntime(2728): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-04 20:07:15.691: E/AndroidRuntime(2728): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
09-04 20:07:15.691: E/AndroidRuntime(2728): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
09-04 20:07:15.691: E/AndroidRuntime(2728): ... 11 more
I would get google map on my emulator.
I followed the instructions on
When I run the application an error's message appears:Unfortunately DemoGoogleMapsV2 has stopped.
my androidmanifest.xml:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.demogooglemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.demogooglemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- The following two permissions are not required to use
Google Maps Android API, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API_KEY"/>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
my activity_main.xml:
<android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
my MainActivity.java:
package com.demogooglemapsv2;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
the log error:
09-04 17:43:51.170: E/Trace(1477): error opening trace file: No such
file or directory (2) 09-04 17:43:53.449: E/AndroidRuntime(1477):
FATAL EXCEPTION: main 09-04 17:43:53.449: E/AndroidRuntime(1477):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.demogooglemapsv2/com.demogooglemapsv2.MainActivity}:
android.view.InflateException: Binary XML file line #11: Error
inflating class fragment 09-04 17:43:53.449: E/AndroidRuntime(1477):
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.app.ActivityThread.access$600(ActivityThread.java:141) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.os.Handler.dispatchMessage(Handler.java:99) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.os.Looper.loop(Looper.java:137) 09-04 17:43:53.449:
E/AndroidRuntime(1477): at
android.app.ActivityThread.main(ActivityThread.java:5041) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
java.lang.reflect.Method.invokeNative(Native Method) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
java.lang.reflect.Method.invoke(Method.java:511) 09-04 17:43:53.449:
E/AndroidRuntime(1477): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
dalvik.system.NativeStart.main(Native Method) 09-04 17:43:53.449:
E/AndroidRuntime(1477): Caused by: android.view.InflateException:
Binary XML file line #11: Error inflating class fragment 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.view.LayoutInflater.inflate(LayoutInflater.java:489) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.app.Activity.setContentView(Activity.java:1881) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
com.demogooglemapsv2.MainActivity.onCreate(MainActivity.java:17) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.app.Activity.performCreate(Activity.java:5104) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-04 17:43:53.449: E/AndroidRuntime(1477): ... 11 more 09-04
17:43:53.449: E/AndroidRuntime(1477): Caused by:
java.lang.IllegalStateException: The meta-data tag in your app's
AndroidManifest.xml does not have the right value. Expected 5089000
but found 0. You must have the following declaration within the
element: 09-04
17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.common.GooglePlayServicesUtil.A(Unknown Source)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown
Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.maps.internal.u.I(Unknown Source) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.maps.internal.u.H(Unknown Source) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.maps.SupportMapFragment$b.jz(Unknown Source)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.maps.SupportMapFragment$b.a(Unknown Source)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.dynamic.a.a(Unknown Source) 09-04 17:43:53.449:
E/AndroidRuntime(1477): at
com.google.android.gms.dynamic.a.onInflate(Unknown Source) 09-04
17:43:53.449: E/AndroidRuntime(1477): at
com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown
Source) 09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:291)
09-04 17:43:53.449: E/AndroidRuntime(1477): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
09-04 17:43:53.449: E/AndroidRuntime(1477): ... 21 more
Replace FragmentActivity in place of Activity, make sure you are entering right api key.
And in place of
com.google.android.gms.maps.MapFragment
use
com.google.android.gms.maps.SupportMapFragment
Make sure google play services is installed on your device. That's why try to run the application on real device not on the emulator.
Add the following activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
/>
</LinearLayout>
add this tag in your menifest file
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Hope your project and google-play-services_lib both are in same workspace and you have added it as library project in your application. If your API-Key is ok then you need to change like this.
1. add this meta-data inside application tag in manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
2. As minSdkVersion="8" you should use SupportMapFragment so activity_main.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
3. Instead of Activity you should extend FragmentActivity and use SupportFragmentManager()
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap();
}
}
Try to run it on real device or Genymotion's emulator after installing
google-play-service. Otherwise you will face a crash
I'm trying to run my start my app, but i get a weird error. I've changed my OS but I've imported my projects in my Workspace. What can be wrong? Every thing is added to the maniferst file like is should, and this app was running nice before I change my OS.
12-13 18:48:10.578: W/dalvikvm(19830): Unable to resolve superclass of Lcom/darkovski/quran/Main; (56)
12-13 18:48:10.578: W/dalvikvm(19830): Link of class 'Lcom/darkovski/quran/Main;' failed
12-13 18:48:10.578: D/AndroidRuntime(19830): Shutting down VM
12-13 18:48:10.578: W/dalvikvm(19830): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
12-13 18:48:10.598: E/AndroidRuntime(19830): FATAL EXCEPTION: main
12-13 18:48:10.598: E/AndroidRuntime(19830): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.darkovski.quran/com.darkovski.quran.Main}: java.lang.ClassNotFoundException: com.darkovski.quran.Main
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1891)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.access$600(ActivityThread.java:127)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.os.Handler.dispatchMessage(Handler.java:99)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.os.Looper.loop(Looper.java:137)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.main(ActivityThread.java:4441)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.reflect.Method.invokeNative(Native Method)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.reflect.Method.invoke(Method.java:511)
12-13 18:48:10.598: E/AndroidRuntime(19830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-13 18:48:10.598: E/AndroidRuntime(19830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-13 18:48:10.598: E/AndroidRuntime(19830): at dalvik.system.NativeStart.main(Native Method)
12-13 18:48:10.598: E/AndroidRuntime(19830): Caused by: java.lang.ClassNotFoundException: com.darkovski.quran.Main
12-13 18:48:10.598: E/AndroidRuntime(19830): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
12-13 18:48:10.598: E/AndroidRuntime(19830): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
12-13 18:48:10.598: E/AndroidRuntime(19830): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1882)
12-13 18:48:10.598: E/AndroidRuntime(19830): ... 11 more
Here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.darkovski.quran"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.darkovski.quran.Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.darkovski.quran.Playlist"
android:screenOrientation="portrait" />
<activity
android:name="com.darkovski.quran.AlbumDetails"
android:screenOrientation="portrait" />
<service
android:name=".MediaPlayerService"
android:enabled="true" />
<activity
android:name="com.darkovski.quran.Favorites"
android:screenOrientation="portrait" />
<activity
android:name="com.darkovski.quran.DownloadManager"
android:screenOrientation="portrait" />
</application>
</manifest>
This has nothing to do with Manifest. It is because somehow the super class of your class com/darkovski/quran/Main is not getting loaded in the apk which leads to a class not found.
Try cleaning and rebuilding the project or restarting eclipse. Just check if all the libraries are present in the new workspace and are build properly.
am getting this exception:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{business.premium/business.premium.Problemio}:
java.lang.ClassNotFoundException: business.premium.Problemio
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
... 11 more
java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
it says that class is not there, but it IS there. I tried to configure things in my project's build path, but not too sure what to tweak there.
And here is how I start my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="business.premium"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:name="MyApplication"
android:debuggable="true">
<activity
android:name=".Problemio"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any thoughts on how to solve this, or what to look into? Thanks!
Its because you specified the "android:name" attribute in the application node in the manifest file.
Do not use the android:name attribute!
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
This answer is taken from: java.lang.ClassNotFoundException on working app
I made an App. and since I just wanted to test some functions before adding them to the App,
I decided to copy my project into a new Project. When I tried to run the new project, the app crashes and the log-cat output is as follows.
Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidbook.MP"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="true">
<activity
android:name=".MPActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="AddLocationActivity"></activity>
<activity android:name="MPData"></activity>
<activity android:name="MyLocations"></activity>
<activity android:name="MPInfo"></activity>
<activity android:name="Navigation"></activity>
</application>
LogCat:
05-21 15:30:03.710: E/AndroidRuntime(11294): FATAL EXCEPTION: main
05-21 15:30:03.710: E/AndroidRuntime(11294): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.androidbook.MP/com.androidbook.MP.MPActivity}:
java.lang.ClassNotFoundException: com.androidbook.MP.MPActivity in loader
dalvik.system.PathClassLoader[/data/app/com.androidbook.MP-1.apk]
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.os.Looper.loop(Looper.java:130)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.reflect.Method.invoke(Method.java:507)
05-21 15:30:03.710: E/AndroidRuntime(11294): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-21 15:30:03.710: E/AndroidRuntime(11294): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-21 15:30:03.710: E/AndroidRuntime(11294): at dalvik.system.NativeStart.main(Native Method)
05-21 15:30:03.710: E/AndroidRuntime(11294): Caused by: java.lang.ClassNotFoundException: com.androidbook.MP.MPActivity in loader dalvik.system.PathClassLoader[/data/app/com.androidbook.MP-1.apk]
05-21 15:30:03.710: E/AndroidRuntime(11294): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
05-21 15:30:03.710: E/AndroidRuntime(11294): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
05-21 15:30:03.710: E/AndroidRuntime(11294): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
05-21 15:30:03.710: E/AndroidRuntime(11294): ... 11 more
Check your Manifest file, if the activity is to be declared.
for Ex:
<application>
<activity android:name=".MyActivity" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Look through all the files in your new project and make sure they aren't referencing classes from the old project.
I think I found the solution, i should have checked that, the package name of the new project is included in the manifest file as for an example
"package="com.androidbook.MPTest" ..
my mistake is the i used the package name of the old project as a package name of the new project.