Android Library Project casting error on extended Application class - android

I am whitelabeling my app. To do this, I've:
Converted my Android Application Project into an Android Library Project. We'll call it com.mylibraryproject.app.
Created a new project. We'll call it com.example.testproject.
Added my Android Library Project as a library of my new Android Application Project.
Copied the manifest from my Android Library Project into the manifest for my new Android Application Project and referenced the Activities appropriately.
Example:
<activity
android:name="com.mylibraryproject.app.activity.MyActivity"
android:screenOrientation="portrait" >
</activity>
However, I'm having a crash when my new Android Application Project runs.
The library project contains a class, we'll call it MyApp, that extends Application. All over this project, there are references to (MyApp)getApplicationContext().
When the above line is hit, the below exception is thrown. How do I avoid this?
Update:
Here is the full onResume() method and log cat:
#Override
protected void onResume() {
super.onResume();
MyApp app = (MyApp)getApplication();
if (app.getUserId() == -1 && !app.getUserConnected() && app.loadLastUser()) {
updateDisplay();
} else if (!mBack && app.getUserConnected()) {
updateDisplay();
}
}
Here is the exception
02-21 13:13:11.169: E/AndroidRuntime(469): FATAL EXCEPTION: main
02-21 13:13:11.169: E/AndroidRuntime(469): java.lang.RuntimeException: Unable to resume activity {com.example.testproject/com.mylibraryproject.app.activity.MyActivity}: java.lang.ClassCastException: android.app.Application
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.os.Looper.loop(Looper.java:130)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-21 13:13:11.169: E/AndroidRuntime(469): at java.lang.reflect.Method.invokeNative(Native Method)
02-21 13:13:11.169: E/AndroidRuntime(469): at java.lang.reflect.Method.invoke(Method.java:507)
02-21 13:13:11.169: E/AndroidRuntime(469): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-21 13:13:11.169: E/AndroidRuntime(469): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-21 13:13:11.169: E/AndroidRuntime(469): at dalvik.system.NativeStart.main(Native Method)
02-21 13:13:11.169: E/AndroidRuntime(469): Caused by: java.lang.ClassCastException: android.app.Application
02-21 13:13:11.169: E/AndroidRuntime(469): at com.mylibraryproject.app.activity.MyActivity.onResume(MyActivity.java:277)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.Activity.performResume(Activity.java:3832)
02-21 13:13:11.169: E/AndroidRuntime(469): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
02-21 13:13:11.169: E/AndroidRuntime(469): ... 12 more
Line 277 is this line:
MyApp app = (MyApp)getApplication();

Application an ApplicationContext aren't the same thing. You need to cast a getApplication() result instead
Of course, casting just says that "I know this object is an xyz so let me treat it as that" ... it doesn't actually transmute one object into another type
Edit:
Change your onResume like below
#Override
protected void onResume() {
super.onResume();
MyApp app = (MyApp)getApplication();
if (app.getUserId() == -1 && !app.getUserConnected() && app.loadLastUser()) {
updateDisplay();
} else if (!mBack && app.getUserConnected()) {
updateDisplay();
}
}
<application android:name="com.mypackage.MyApp"
....>

Related

My app freezes crashes when it's supposed to go to the next activity

I don't know why the app crashes whenever it's supposed to go to the next Activity. I made a practice app that works as it should when using the same format. I uploaded the files to gist.github.
The error is
1216-1216/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
at com.example.chiozokamalu.newfreshstart.MainActivity.onClick(MainActivity.java:164)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
On line 164 of MainActivity.java:
questionView.setText(questions[questionIndex]); // set the text to the next question
EDIT: After Varun helped me, I get a new error which is
1307-1307/com.example.chiozokamalu.newfreshstart E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chiozokamalu.newfreshstart/com.example.chiozokamalu.newfreshstart.Results1}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.chiozokamalu.newfreshstart.Results1.onCreate(Results1.java:58)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3683)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
            at dalvik.system.NativeStart.main(Native Method)
The questions array at line no. 164 is going out of bound that means questionIndex is greater than the total length of the questions array. So you should add a check on the length before extracting value from the array.
You have added the check but after that you incremented the value so either you modify the if condition to if (questionIndex < questions.length -1)
or modify the questionIndex variable before the if condition
You are getting problem because you haven't initiated resultView9 that is why it is null and giving nullpointer, just initiatlise it as you done with other and everything is fine. You have initialised the resultView8 twice just add resultview9 over there

Eclipse Android exceptions are hidden

The code in my book created a NPE for me to see. But, when I open the logcat in ddms, I cannot see all the errors (it says 11 more). How do I see all the exceptions ? Please see the photo below -
EDIT - Image for full trace posted. Also posting text of trace by copy pasting.
Image -
D/QuizActivity(836): onCreate(Bundle) called
D/AndroidRuntime(836): Shutting down VM
W/dalvikvm(836): threadid=1: thread exiting with uncaught exception (group=0x41465700)
E/AndroidRuntime(836): FATAL EXCEPTION: main
E/AndroidRuntime(836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.geoquiz/com.bignerdranch.android.geoquiz.QuizActivity}: java.lang.NullPointerException
E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
E/AndroidRuntime(836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
E/AndroidRuntime(836): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime(836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
E/AndroidRuntime(836): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(836): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(836): at android.app.ActivityThread.main(ActivityThread.java:5103)
E/AndroidRuntime(836): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(836): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
E/AndroidRuntime(836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime(836): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(836): Caused by: java.lang.NullPointerException
E/AndroidRuntime(836): at com.bignerdranch.android.geoquiz.QuizActivity.updateQuestion(QuizActivity.java:47)
E/AndroidRuntime(836): at com.bignerdranch.android.geoquiz.QuizActivity.onCreate(QuizActivity.java:111)
E/AndroidRuntime(836): at android.app.Activity.performCreate(Activity.java:5133)
E/AndroidRuntime(836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime(836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
E/AndroidRuntime(836): ... 11 more
You dont usually need the whole stack trace, the main thing to look for is "caused by" message and the class(TAG) which is causing the exception
Use try catch block and Java Doc
printStackTrace to see the full stack trace.
try {
// Expected Exception Rasing Line
} catch (Exception e) {
e.printStackTrace();
}

Selecting an item in ListFragment list programmatically

I've made my Android app tablet optimized and I followed the tutorial here:
Everything is great, but I am trying to select an item (say, the 1st item) with a button in the ActionBar.
I tried this answer to use performItemClick but on I've got error reports of java.lang.IllegalStateException
in android.support.v4.app.ListFragment.ensureList, java.lang.IllegalStateException: Content view not yet created, and java.lang.NullPointerException
in android.content.ComponentName.<init>
I've tried checking if the ListView is null and still get the error reports on the Play Store. How do I properly select an item in my list programmatically?
Update to add logcat and the code is virtually identical to the tutorials in the links:
Logcat A:
java.lang.IllegalStateException: Content view not yet created
at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328)
at android.support.v4.app.ListFragment.getListView(ListFragment.java:222)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:69)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2606)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1045)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java:592)
at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:149)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17273)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
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:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Logcat B:
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2874)
at com.ccwilcox.meteorshower.MeteorList.showMeteorDetails(MeteorList.java:86)
at com.ccwilcox.meteorshower.MeteorList.onListItemClick(MeteorList.java:62)
at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.ListView.performItemClick(ListView.java:3701)
at com.ccwilcox.meteorshower.MainActivity.viewUpcomingEvent(MainActivity.java:648)
at com.ccwilcox.meteorshower.MainActivity.onOptionsItemSelected(MainActivity.java:534)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:361)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:779)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:861)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Update 2
And here is the code that is causing the problem:
if (mListFragment.listView != null) {
mListFragment.listView.performItemClick(mListFragment.listView.getAdapter().getView(position, null, null), position, mListFragment.listView.getAdapter().getItemId(position));
}

i get allways this errors when i execute web service application, can you help me please?

02-21 14:00:32.442: W/WindowManager(88): Failure taking screenshot for (180x300) to layer 21010
02-21 14:00:32.621: W/NetworkManagementSocketTagger(88): setKernelCountSet(10004, 1) failed with errno -2
02-21 14:00:34.962: W/NetworkManagementSocketTagger(88): setKernelCountSet(10061, 0) failed with errno -2
02-21 14:00:38.403: D/AndroidRuntime(583): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-21 14:00:38.403: D/AndroidRuntime(583): CheckJNI is ON
02-21 14:00:40.521: D/AndroidRuntime(583): Calling main entry com.android.commands.pm.Pm
02-21 14:00:40.592: D/AndroidRuntime(583): Shutting down VM
02-21 14:00:40.611: I/AndroidRuntime(583): NOTE: attach of thread 'Binder Thread #3' failed
02-21 14:00:40.621: D/dalvikvm(583): GC_CONCURRENT freed 100K, 78% free 462K/2048K, paused 2ms+2ms
02-21 14:00:40.621: D/jdwp(583): Got wake-up signal, bailing out of select
02-21 14:00:40.621: D/dalvikvm(583): Debugger has detached; object registry had 1 entries
02-21 14:00:41.421: D/AndroidRuntime(596): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-21 14:00:41.421: D/AndroidRuntime(596): CheckJNI is ON
02-21 14:00:42.471: D/AndroidRuntime(596): Calling main entry com.android.commands.am.Am
02-21 14:00:42.521: I/ActivityManager(88): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.pfe/.SoappActivity} from pid 596
02-21 14:00:42.531: W/WindowManager(88): Failure taking screenshot for (180x300) to layer 21005
02-21 14:00:42.611: W/NetworkManagementSocketTagger(88): setKernelCountSet(10061, 1) failed with errno -2
02-21 14:00:43.221: W/System.err(536): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
02-21 14:00:42.661: I/AndroidRuntime(596): NOTE: attach of thread 'Binder Thread #3' failed
02-21 14:00:42.661: D/dalvikvm(596): GC_CONCURRENT freed 101K, 77% free 483K/2048K, paused 1ms+3ms
02-21 14:00:42.661: D/jdwp(596): Got wake-up signal, bailing out of select
02-21 14:00:42.671: D/dalvikvm(596): Debugger has detached; object registry had 1 entries
02-21 14:00:43.021: W/System.err(536): android.os.NetworkOnMainThreadException
02-21 14:00:43.021: W/System.err(536): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
02-21 14:00:43.071: W/System.err(536): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
02-21 14:00:43.071: W/System.err(536): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
02-21 14:00:43.081: W/System.err(536): at java.net.InetAddress.getAllByName(InetAddress.java:220)
02-21 14:00:43.081: W/System.err(536): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
02-21 14:00:43.081: W/System.err(536): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
02-21 14:00:43.127: W/System.err(536): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
02-21 14:00:43.127: W/System.err(536): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
02-21 14:00:43.131: W/System.err(536): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
02-21 14:00:43.332: W/System.err(536): at dalvik.system.NativeStart.main(Native Method)
02-21 14:01:30.961: D/dalvikvm(536): GC_CONCURRENT freed 231K, 4% free 10112K/10503K, paused 23ms+23ms
02-21 14:04:36.751: D/gralloc_goldfish(640): Emulator without GPU emulation detected.
02-21 14:05:40.481: D/AndroidRuntime(640): Shutting down VM
02-21 14:05:40.481: W/dalvikvm(640): threadid=1: thread exiting with uncaught exception (group=0x409951f8)
02-21 14:05:40.571: E/AndroidRuntime(640): FATAL EXCEPTION: main
02-21 14:05:40.571: E/AndroidRuntime(640): java.lang.RuntimeException: Unable to create service com.pfe.MonService: java.lang.IllegalArgumentException: provider=network
02-21 14:05:40.571: E/AndroidRuntime(640): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2262)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.app.ActivityThread.access$1600(ActivityThread.java:122)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.os.Looper.loop(Looper.java:137)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.app.ActivityThread.main(ActivityThread.java:4340)
02-21 14:05:40.571: E/AndroidRuntime(640): at java.lang.reflect.Method.invokeNative(Native Method)
02-21 14:05:40.571: E/AndroidRuntime(640): at java.lang.reflect.Method.invoke(Method.java:511)
02-21 14:05:40.571: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-21 14:05:40.571: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-21 14:05:40.571: E/AndroidRuntime(640): at dalvik.system.NativeStart.main(Native Method)
02-21 14:05:40.571: E/AndroidRuntime(640): Caused by: java.lang.IllegalArgumentException: provider=network
02-21 14:05:40.571: E/AndroidRuntime(640): at android.os.Parcel.readException(Parcel.java:1331)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.os.Parcel.readException(Parcel.java:1281)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.location.LocationManager._requestLocationUpdates(LocationManager.java:582)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:446)
02-21 14:05:40.571: E/AndroidRuntime(640): at com.pfe.MonService.onCreate(MonService.java:58)
02-21 14:05:40.571: E/AndroidRuntime(640): at android.app.ActivityThread.handleCreateService(ActivityThread.java:2252)
02-21 14:05:40.571: E/AndroidRuntime(640): ... 10 more
You try to execute network call on main (UI) thread. This is not acceptable, because UI should be responsive and network calls are long in most cases. What you need is to run your code on the other thread using Thread class or AsyncTask. Also, you can check out this question for some details.

Android google map error

In my project eclispe does not debug any error ! but when run it's force to stop
this is my logcat any idea !!!
07-08 11:20:41.494: WARN/dalvikvm(735): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): FATAL EXCEPTION: main
07-08 11:20:41.534: ERROR/AndroidRuntime(735): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.remwebdevelopment.maptest/com.remwebdevelopment.maptest.MapTest}: java.lang.ClassNotFoundException: com.remwebdevelopment.maptest.MapTest in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.remwebdevelopment.maptest-2.apk]
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1544)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.os.Looper.loop(Looper.java:123)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.ActivityThread.main(ActivityThread.java:3647)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at java.lang.reflect.Method.invoke(Method.java:507)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at dalvik.system.NativeStart.main(Native Method)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): Caused by: java.lang.ClassNotFoundException: com.remwebdevelopment.maptest.MapTest in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.remwebdevelopment.maptest-2.apk]
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1536)
07-08 11:20:41.534: ERROR/AndroidRuntime(735): ... 11 more
You have either changed your AndroidManifest.xml to update the application package name without changing the <activity> definition for com.remwebdevelopment.maptest.MapTest or you did not define an <activity> entry for com.remwebdevelopment.maptest.MapTest in your AndroidManifest.xml file.
I had the same problem. My solution (similar to other people's answers) was to use the Manifest editor in eclipse. I just removed the "uses library" entry in the application tab and added it again. It put the node at the bottom of the tree (just before the application tag is closed) and it works now. It used to exist half way up the tree of nodes.
UPDATE
I also found later that I needed to update my project according to this post by running the command android update project -p .
Had this sort of problem today after upgrading to latest ADT/SDK. Also for me the exception was
Unable to instantiate activity
Took me quite a while. Checked that i used google-apis (for maps), uses-library, cleaned the project etc.
Deleting the .project and adding a fresh one (create new android project) finally solved it.

Categories

Resources