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.
Related
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!
I've posted this question on the Amazon Developer Forum and haven't received an answer in 4 days, I've also sent it to Amazon developer support and haven't received an answer in the same time frame, so I'm here, hoping someone can help.
I'm trying to add 'mobile ads' to a new application. I'm working with Eclipse - Helios
In my manifest I have the correct permissions set
I have the Libraries set, I've checked the build path and project properties and things seem fine, The project builds with no issues
In my code
I have inserted the Application Key
I have inserted AdRegistration.enableLogging(true);
I have inserted AdRegistration.enableTesting(true);
When I use 'Run As - Android App' the app crashes with this and select either of my normal testing devices (Kindle Fire or Samsung Galaxy Tab), it builds find and begins to load the apk unto the the device and then this:
07-24 14:30:40.722: E/AndroidRuntime(2904): FATAL EXCEPTION: main
07-24 14:30:40.722: E/AndroidRuntime(2904): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thecountrylife/com.thecountrylife.MenuActivity}: java.lang.ClassNotFoundException: Didn't find class "com.thecountrylife.MenuActivity" on path: /data/app/com.thecountrylife-2.apk:/system/app/MetricsApi-2037410.apk:/system/app/com.amazon.dp.logger.apk
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2142)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.ActivityThread.access$600(ActivityThread.java:146)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1245)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.os.Looper.loop(Looper.java:151)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.ActivityThread.main(ActivityThread.java:5152)
07-24 14:30:40.722: E/AndroidRuntime(2904): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 14:30:40.722: E/AndroidRuntime(2904): at java.lang.reflect.Method.invoke(Method.java:511)
07-24 14:30:40.722: E/AndroidRuntime(2904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-24 14:30:40.722: E/AndroidRuntime(2904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-24 14:30:40.722: E/AndroidRuntime(2904): at dalvik.system.NativeStart.main(Native Method)
07-24 14:30:40.722: E/AndroidRuntime(2904): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.thecountrylife.MenuActivity" on path: /data/app/com.thecountrylife-2.apk:/system/app/MetricsApi-2037410.apk:/system/app/com.amazon.dp.logger.apk
07-24 14:30:40.722: E/AndroidRuntime(2904): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-24 14:30:40.722: E/AndroidRuntime(2904): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-24 14:30:40.722: E/AndroidRuntime(2904): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.Instrumentation.newActivity(Instrumentation.java:1055)
07-24 14:30:40.722: E/AndroidRuntime(2904): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2133)
Any help would be greatly appreciated
Rather than continue to wait for Amazon or beat my head over the issue I simply switched over to Google MobAds, so my manifest is now what Google requires. Thanks anyway.
I've taken the code from Android's own Audio Capture documentation and ran it to achieve just what the docs say. As is, the code crashes when I click the "Start Recording" button and the crash says the following:
FATAL EXCEPTION: main
java.lang.IllegalStateException
at android.media.MediaRecorder.start(Native Method)
**at com.om.shout_o_meter.MainActivity.startRecording(MainActivity.java:130)
at com.om.shout_o_meter.MainActivity.onRecord(MainActivity.java:111)
at com.om.shout_o_meter.MainActivity.access$0(MainActivity.java:109)
at com.om.shout_o_meter.MainActivity$1.onClick(MainActivity.java:38)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
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:4898)
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:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
If I place AudioRecordTest() at the very beginning of the startRecording() method, the crash ceases until I finish the first recording and then press "Start Recording" again, the crash reappears with the following message:
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.om.shout_o_meter.MainActivity.stopRecording(MainActivity.java:135)
at com.om.shout_o_meter.MainActivity.onRecord(MainActivity.java:113)
at com.om.shout_o_meter.MainActivity.access$0(MainActivity.java:109)
at com.om.shout_o_meter.MainActivity$1.onClick(MainActivity.java:38)
at android.view.View.performClick(View.java:4211)
at android.view.View$PerformClick.run(View.java:17267)
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:4898)
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:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
The code I'm using is the exact same code as that of the docs (linked above), and the "MainActivity" file that the exception is pointing to can be found here: http://pastie.org/8682455
Any clue? what baffles me is that the code is pasted as is, straight from the docs, and still it fails..
Thanks
[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 recently published my app to the android play store.
I see a whole lot of error logs from one device in particular. It's a Sony Experia S.
I contacted the owner of the device, and he says he has the latest version of android ( don't know the exact version ).
I heard from a colluege developer that there are more known issieus with sony devices and android.
This app in particular works with fragments... Don't know if this is the problem but... Maybe the sony's don't know how to cope with them.
Does anyone have an idea what this problem could be.
Error logs looks like:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crosscommunications.kvodeventer/com.crosscommunications.kvodeventer.KVODeventerActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crosscommunications.kvodeventer/com.crosscommunications.kvodeventer.TabControllerHome}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
at android.app.ActivityThread.access$600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crosscommunications.kvodeventer/com.crosscommunications.kvodeventer.TabControllerHome}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:1808)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:682)
at android.widget.TabHost.setCurrentTab(TabHost.java:346)
at android.widget.TabHost.addTab(TabHost.java:236)
at com.crosscommunications.kvodeventer.KVODeventerActivity.onCreate(KVODeventerActivity.java:27)
at android.app.Activity.performCreate(Activity.java:4470)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
... 11 more
Caused by: java.lang.NullPointerException
at com.crosscommunications.kvodeventer.KVOHome.onCreateView(KVOHome.java:52)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1136)
at android.app.Activity.performStart(Activity.java:4480)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1940)
... 21 more
Thnx
Just put a null check to your code:
KVOHome Acvitivity, line 52.
at com.crosscommunications.kvodeventer.KVOHome.onCreateView(KVOHome.java:52)
Most probably, Sony sends a null value to your code.