This question already has answers here:
What is a stack trace, and how can I use it to debug my application errors?
(7 answers)
Closed 8 years ago.
I got an issue with an android app I'm trying to develop. When I test it in an emulator with android 4.4.2 (the target sdk version), everything works fine. But when I run the same code in an emulator with the same settings but android 4.3 instead, the app crashes almost immediately with the catlog error below.
Using the android lint in eclipse (right click on project, "Android tools" > "Run lint: check for common error"), I cannot find any code that doesn't correspond with the minSdkVersion (16).
Anyone got suggestions what's going wrong?
Catlog error:
07-24 12:54:14.592: D/AndroidRuntime(1012): Shutting down VM
07-24 12:54:14.592: W/dalvikvm(1012): threadid=1: thread exiting with uncaught exception (group=0x41465700)
07-24 12:54:14.631: E/AndroidRuntime(1012): FATAL EXCEPTION: main
07-24 12:54:14.631: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.protime360_basics/com.example.protime360_basics.MainActivity}: java.lang.NullPointerException
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.os.Looper.loop(Looper.java:137)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-24 12:54:14.631: E/AndroidRuntime(1012): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 12:54:14.631: E/AndroidRuntime(1012): at java.lang.reflect.Method.invoke(Method.java:525)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-24 12:54:14.631: E/AndroidRuntime(1012): at dalvik.system.NativeStart.main(Native Method)
07-24 12:54:14.631: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.example.protime360_basics.MainActivity.loginPopup(MainActivity.java:167)
07-24 12:54:14.631: E/AndroidRuntime(1012): at com.example.protime360_basics.MainActivity.onCreate(MainActivity.java:61)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.Activity.performCreate(Activity.java:5133)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-24 12:54:14.631: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
07-24 12:54:14.631: E/AndroidRuntime(1012): ... 11 more
I found the problem thanks to #codeMagic and #Chris Stratton. Line 167 in my code was
if(!username.equals(null)){
I changed that to
if(username != null && !username.isEmpty()){
=> Problem solved!
Related
I just loaded my app created by cocos2dx-3.10 and when I open with it an AVD (again I haven't done any modifications to the app) the app crashes and gives the error: Unfortunately, libcocos2dx has crashed.
here is what I get in my android Monitor:
03-05 18:34:56.668 1435-1435/? D/dalvikvm: Not late-enabling CheckJNI (already on)
03-05 18:34:56.989 1435-1435/com.trying.name E/Trace: error opening trace file: No such file or directory (2)
03-05 18:34:57.419 1435-1435/com.trying.name D/AndroidRuntime: Shutting down VM
03-05 18:34:57.419 1435-1435/com.trying.name W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb2f2b288)
03-05 18:34:57.518 1435-1435/com.trying.name E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:248)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:263)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-05 18:35:11.559 1435-1435/? I/Process: Sending signal. PID: 1435 SIG: 9
Hello all,
I tried to find an answer online for this problem, but i cannot find a way to fix my problem...
So maybe some of you guys know what i can do to solve it.
So i have a game ( surface view and thread that draws on the cavnas and all that gamy stuff ) and everything works fine in portrait mode, but i want my game to be played in landscape mode, so i have changed the mode in the android manifest like so:
android:screenOrientation="landscape"
Which works fine, everything is the same, except when i want to close the activity ( call onPause method ). When i get the error that the app needs to be force closed.
Now some people solved their problem by adding
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
To their manifest files, but that doesn't do the trick for me, i still keep getting NullPointerException.
Here is the logcat:
07-24 21:27:12.160: E/AndroidRuntime(5272): FATAL EXCEPTION: main
07-24 21:27:12.160: E/AndroidRuntime(5272): java.lang.RuntimeException: Unable to pause activity {com.example.fishtruck/com.example.fishtruck.Start}: java.lang.NullPointerException
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2706)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2662)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2640)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.access$800(ActivityThread.java:123)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1154)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.os.Looper.loop(Looper.java:137)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-24 21:27:12.160: E/AndroidRuntime(5272): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 21:27:12.160: E/AndroidRuntime(5272): at java.lang.reflect.Method.invoke(Method.java:511)
07-24 21:27:12.160: E/AndroidRuntime(5272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
07-24 21:27:12.160: E/AndroidRuntime(5272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
07-24 21:27:12.160: E/AndroidRuntime(5272): at dalvik.system.NativeStart.main(Native Method)
07-24 21:27:12.160: E/AndroidRuntime(5272): Caused by: java.lang.NullPointerException
07-24 21:27:12.160: E/AndroidRuntime(5272): at com.example.fishtruck.Start.onPause(Start.java:113)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.Activity.performPause(Activity.java:4563)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1197)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2693)
07-24 21:27:12.160: E/AndroidRuntime(5272): ... 12 more
And (not sure if relevant but what the heck ) here is how i call the onPause method:
view.stopThread();
this.finish(); //this is called in the activity and view = surfaceView
And the stopThread() method is called like so:
if(thread!=null){
thread.interrupt();
thread.setRunning(false);
isStopped = true;
thread = null;
}
What object do you have on row 113 in Start.java? The object you have there is not initiated correctly (it is null) which makes your app crash.
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();
}
[SOLVED]
I have the following structure in my code:
ListView accountListView = (ListView) findViewById(R.id.accountListing);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_view_item, R.id.nameTextView, currentAccounts);
accountListView.setAdapter(adapter);
accountListView.performItemClick(null, 0, 0);
currentAccounts is an array, and it has data on it.
When I try to performItemClick after setting the adapter, I get a NullPointerException.
I also override the OnKeyPress, to run the "performItemClick" and it works fine.
I would like to know WHY it doesn't work when trying to perform the click after setting the adapter. (after some debugging I saw that the lastVisiblePosition is -1) WHY?
[EDIT]
Using ((ListView)findViewById(R.id.accountListing)).performItemClick(null, 0, 0); works, EXCEPT, if used right after setting the adapter. (look at the comments for more info)
[EDIT 2]
Stack Trace:
07-24 13:07:56.710: E/AndroidRuntime(9455): FATAL EXCEPTION: main
07-24 13:07:56.710: E/AndroidRuntime(9455): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.device/com.app.device.WelcomeActivity}: java.lang.NullPointerException
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.os.Looper.loop(Looper.java:137)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.ActivityThread.main(ActivityThread.java:4895)
07-24 13:07:56.710: E/AndroidRuntime(9455): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 13:07:56.710: E/AndroidRuntime(9455): at java.lang.reflect.Method.invoke(Method.java:511)
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
07-24 13:07:56.710: E/AndroidRuntime(9455): at dalvik.system.NativeStart.main(Native Method)
07-24 13:07:56.710: E/AndroidRuntime(9455): Caused by: java.lang.NullPointerException
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.app.device.WelcomeActivity.unselectViews(WelcomeActivity.java:1637)
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.app.device.WelcomeActivity.access$24(WelcomeActivity.java:1632)
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.app.device.WelcomeActivity$27.onItemClick(WelcomeActivity.java:1447)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.app.device.WelcomeActivity.UpdateAccountList(WelcomeActivity.java:1653)
07-24 13:07:56.710: E/AndroidRuntime(9455): at com.app.device.WelcomeActivity.onCreate(WelcomeActivity.java:238)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.Activity.performCreate(Activity.java:5163)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-24 13:07:56.710: E/AndroidRuntime(9455): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
07-24 13:07:56.710: E/AndroidRuntime(9455): ... 11 more
Thanks in advance!
[SOLUTION]
I was trying to performItemClick on the onCreate() method, but the screen is not fully visible to the user. Using onWindowFocusChanged() worked! onWindowFocusChanged() on Android Documentation.
Thanks everybody.
You are passing null as parameter for the perfomItemClick, have you tried:
ListView accountListView = (ListView) findViewById(R.id.accountListing);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_view_item, R.id.nameTextView, currentAccounts);
accountListView.setAdapter(adapter);
accountListView.performItemClick(adapter, 0, 0);
Hope this helps...
Regards!
I think you have to pass accountListView in parameter to performItemClick instead of null .
[SOLVED]
I was trying to performItemClick on the onCreate() method, but the screen is not fully visible to the user. Using onWindowFocusChanged() worked! onWindowFocusChanged() on Android Documentation.
Thanks everybody.
I am developing one android application and in that app I am trying to use Gson Library for Json serialization and de-serialization. I downloaded the library from the following link:-
http://code.google.com/p/google-gson/downloads/list
I included the gson-2.2.2.jar in Java Build Path, but the application crashes at run time when constructing Gson object:-
Gson gson = new Gson();
in logcat I get
07-24 14:53:21.648: E/dalvikvm(488): Could not find class 'com.google.gson.Gson', referenced from method com.google.gson.examples.android.GsonProguardExampleActivity.onCreate
07-24 14:53:21.648: W/dalvikvm(488): VFY: unable to resolve new-instance 10 (Lcom/google/gson/Gson;) in Lcom/google/gson/examples/android/GsonProguardExampleActivity;
07-24 14:53:21.668: D/dalvikvm(488): VFY: replacing opcode 0x22 at 0x0010
07-24 14:53:21.668: D/dalvikvm(488): VFY: dead code 0x0012-007a in Lcom/google/gson/examples/android/GsonProguardExampleActivity;.onCreate (Landroid/os/Bundle;)V
07-24 14:53:21.788: D/AndroidRuntime(488): Shutting down VM
07-24 14:53:21.788: W/dalvikvm(488): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-24 14:53:21.814: E/AndroidRuntime(488): FATAL EXCEPTION: main
07-24 14:53:21.814: E/AndroidRuntime(488): java.lang.NoClassDefFoundError: com.google.gson.Gson
07-24 14:53:21.814: E/AndroidRuntime(488): at com.google.gson.examples.android.GsonProguardExampleActivity.onCreate(GsonProguardExampleActivity.java:40)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.os.Looper.loop(Looper.java:123)
07-24 14:53:21.814: E/AndroidRuntime(488): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-24 14:53:21.814: E/AndroidRuntime(488): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 14:53:21.814: E/AndroidRuntime(488): at java.lang.reflect.Method.invoke(Method.java:521)
07-24 14:53:21.814: E/AndroidRuntime(488): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-24 14:53:21.814: E/AndroidRuntime(488): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-24 14:53:21.814: E/AndroidRuntime(488): at dalvik.system.NativeStart.main(Native Method)
Error is:-
07-24 14:53:21.814: E/AndroidRuntime(488): java.lang.NoClassDefFoundError: com.google.gson.Gson
Also, If I include full source of Gson library as another package in my project it all works well.
What am I doing wrong, is this the correct jar??
Seems you have kept the jar file inside lib folder, rather the name should be changed to libs. This was updated newer revisions of ADT (revision 17 onwards).