NoClassDefFoundError in Cocos2D sample - android

I am getting the same problem this question, but the solution didn't work for me. I've included my JAR in build path. What wrong am I doing?
I am using the same example.
Here's the crash log:
07-08 04:04:33.440: E/AndroidRuntime(751): FATAL EXCEPTION: main
07-08 04:04:33.440: E/AndroidRuntime(751): java.lang.NoClassDefFoundError: org.cocos2d.opengl.CCGLSurfaceView
07-08 04:04:33.440: E/AndroidRuntime(751): at a.b.Cocos2DGameActivity.onCreate(Cocos2DGameActivity.java:22)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.Activity.performCreate(Activity.java:4465)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.os.Looper.loop(Looper.java:137)
07-08 04:04:33.440: E/AndroidRuntime(751): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-08 04:04:33.440: E/AndroidRuntime(751): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 04:04:33.440: E/AndroidRuntime(751): at java.lang.reflect.Method.invoke(Method.java:511)
07-08 04:04:33.440: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-08 04:04:33.440: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-08 04:04:33.440: E/AndroidRuntime(751): at dalvik.system.NativeStart.main(Native Method)

I recomend you to change libraries to cocos2d-x, because cocos2d for android won't be updated anymore.
Cocos2d-x works in C++, and uses JNI (Java native interface) to work. Here is all the info you will need to start using it.

I guess the problem was in the JAR file. Fortunately the project is open source, so I added the source file and it stopped giving me error. There's a source code available on that tutorial which also uses the source files, instead of the JAR.

I get the same problem. And I copy the source code to src instead of including the jar.
And you must change the project's jre version to 1.6

Related

Control how android kills my app

I have an android application with a lot of activities and services. If I open another application while my application is running and android needs resources kills my application and I receive NullPointerException error messages like this:
07-08 18:14:48.567: E/AndroidRuntime(16300): FATAL EXCEPTION: main
07-08 18:14:48.567: E/AndroidRuntime(16300): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{icg.android.start/icg.android.web.CustomWebActivity}: java.lang.NullPointerException
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.os.Looper.loop(Looper.java:137)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-08 18:14:48.567: E/AndroidRuntime(16300): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 18:14:48.567: E/AndroidRuntime(16300): at java.lang.reflect.Method.invoke(Method.java:511)
07-08 18:14:48.567: E/AndroidRuntime(16300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-08 18:14:48.567: E/AndroidRuntime(16300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-08 18:14:48.567: E/AndroidRuntime(16300): at dalvik.system.NativeStart.main(Native Method)
07-08 18:14:48.567: E/AndroidRuntime(16300): Caused by: java.lang.NullPointerException
07-08 18:14:48.567: E/AndroidRuntime(16300): at icg.guice.Dependencies.injectDependencies(Dependencies.java:238)
07-08 18:14:48.567: E/AndroidRuntime(16300): at icg.guice.GuiceActivity.<init>(GuiceActivity.java:9)
07-08 18:14:48.567: E/AndroidRuntime(16300): at icg.android.web.CustomWebActivity.<init>(CustomWebActivity.java:16)
07-08 18:14:48.567: E/AndroidRuntime(16300): at java.lang.Class.newInstanceImpl(Native Method)
07-08 18:14:48.567: E/AndroidRuntime(16300): at java.lang.Class.newInstance(Class.java:1319)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
07-08 18:14:48.567: E/AndroidRuntime(16300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
I tried to detect if android kills my activities but searching I found that there is no way to do that.
At least, is possible avoid to show the error message on the device screen? I prefer that the application crashes silently.
Thanks
There is no way to stop Android from killing your services/process if it is in need of more resources. In that case you need to use the onPause() and onDestroy() methods to shut down any services that you may not need and to release as many resources back to Android as possible.
Then you have to utilize onResume() to ensure that the proper activities/services are present when the application is in focus. This might help eliminate the NullPointerException and crashing.

Open Web Browser from App - Always Crashes

I'm trying to open a web browser from my app using:
Intent browser = new Intent(Intent.ACTION_VIEW, Uri.parse("http://developer.android.com/"));
startActivity(browser);
But the app just crashes:
08-07 17:18:29.912: E/AndroidRuntime(751): FATAL EXCEPTION: main
08-07 17:18:29.912: E/AndroidRuntime(751): java.lang.NullPointerException
08-07 17:18:29.912: E/AndroidRuntime(751): at android.app.Activity.startActivityForResult(Activity.java:3131)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.app.Activity.startActivity(Activity.java:3237)
08-07 17:18:29.912: E/AndroidRuntime(751): at com.Co.DrumKit$9.onClick(DrumKit.java:658)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.view.View.performClick(View.java:3110)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.view.View$PerformClick.run(View.java:11934)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.os.Handler.handleCallback(Handler.java:587)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.os.Handler.dispatchMessage(Handler.java:92)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.os.Looper.loop(Looper.java:132)
08-07 17:18:29.912: E/AndroidRuntime(751): at android.app.ActivityThread.main(ActivityThread.java:4123)
08-07 17:18:29.912: E/AndroidRuntime(751): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 17:18:29.912: E/AndroidRuntime(751): at java.lang.reflect.Method.invoke(Method.java:491)
08-07 17:18:29.912: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-07 17:18:29.912: E/AndroidRuntime(751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-07 17:18:29.912: E/AndroidRuntime(751): at dalvik.system.NativeStart.main(Native Method)

DatePicker giving NullPointerException when setting Date

I changed the locale of Android Emulator to Arabic to test the Arabic version of my application. The date picker appears as shown below,
Although the DatePicker was working perfectly in the English version of my application, now t is giving me the following error.
07-08 11:13:44.544: E/AndroidRuntime(696): FATAL EXCEPTION: main
07-08 11:13:44.544: E/AndroidRuntime(696): java.lang.NullPointerException
07-08 11:13:44.544: E/AndroidRuntime(696): at org.digitalhealthagency.elaj.gui.AppointmentReservationActivity$DoctorWorkingDaysTask.access$2(AppointmentReservationActivity.java:927)
07-08 11:13:44.544: E/AndroidRuntime(696): at org.digitalhealthagency.elaj.gui.AppointmentReservationActivity$5.onDateSet(AppointmentReservationActivity.java:454)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.app.DatePickerDialog.tryNotifyDateSet(DatePickerDialog.java:148)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.app.DatePickerDialog.onStop(DatePickerDialog.java:155)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.app.Dialog.dismissDialog(Dialog.java:326)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.app.Dialog.dismiss(Dialog.java:302)
07-08 11:13:44.544: E/AndroidRuntime(696): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:170)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.os.Looper.loop(Looper.java:137)
07-08 11:13:44.544: E/AndroidRuntime(696): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-08 11:13:44.544: E/AndroidRuntime(696): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 11:13:44.544: E/AndroidRuntime(696): at java.lang.reflect.Method.invoke(Method.java:511)
07-08 11:13:44.544: E/AndroidRuntime(696): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-08 11:13:44.544: E/AndroidRuntime(696): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-08 11:13:44.544: E/AndroidRuntime(696): at dalvik.system.NativeStart.main(Native Met
hod)
Am I missing something I should be doing for the Arabic version?
I found out that this problem appeared when I tested on an Android 4.1 emulator. The DatePickerDialog looks quite different and has one button instead of two, but my code is working normally on Android 4.0.3 emulators and below.
Posted another question here Android: Android 4.1 Emulator Invoking onDateSet Twice from DatePicker Dialog
I can't think of anything specific to Arabic. In the absence of any code, the best I can do is suggest some debugging techniques.
If you look at the code on line 927 of AppointmentReservationActivity.java, I suspect whatever you're accessing a method/field of will give it away.
If you don't see it right away, try setting a breakpoint on that line and check your variables.

Android Initial error in Emulator on Application Start

I am faced with this weird error. Whenever I start my application on my emulator, I get a message in the Emulator saying that Unfortunately,Search has stopped.
My LogCat also shows some error but after a few seconds, the application runs properly without any hassles.
But, every time I upload and install the application on the emulator I get this error.
I realise that it does not cause any trouble to the application as after the initial error, everything runs fine but still I would very much like to know the cause of such an error.
Here is what my LogCat displays.
07-08 13:47:38.262: E/AndroidRuntime(1931): FATAL EXCEPTION: main
07-08 13:47:38.262: E/AndroidRuntime(1931): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3938)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.ActivityThread.access$1300(ActivityThread.java:123)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.os.Looper.loop(Looper.java:137)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-08 13:47:38.262: E/AndroidRuntime(1931): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 13:47:38.262: E/AndroidRuntime(1931): at java.lang.reflect.Method.invoke(Method.java:511)
07-08 13:47:38.262: E/AndroidRuntime(1931): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-08 13:47:38.262: E/AndroidRuntime(1931): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-08 13:47:38.262: E/AndroidRuntime(1931): at dalvik.system.NativeStart.main(Native Method)
07-08 13:47:38.262: E/AndroidRuntime(1931): Caused by: java.lang.NullPointerException
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
07-08 13:47:38.262: E/AndroidRuntime(1931): at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
07-08 13:47:38.262: E/AndroidRuntime(1931): ... 11 more
Any idea what might be the cause ?
Make sure you correctly declared the android:name attribute of your application tag in the AndroidManifest.xml file.
See this answer here for an explanation on the Unable to instantiate application android.app.Application logcat error.
Make an entry in androidManifest.xml with the application name
<application
android:name=<name of the class that extends Application>
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >

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