NullpointerException from spinner.java:828 dismiss - android

I'm new to java/android and trying to help out with an open source project. I decided I could learn the most from trying to fix bugs and so I've been running Monkey on the app to start generating crash reports with bugsense (I don't have access to play.google crash reports). I consistently run into the crash below and since it doesn't identify where in the code the app is having problems, I'm not even sure what exactly the problem is. I'm not asking for a line by line fix (although it is open source) but some helpful hints would be much appreciated.
Complete Repo: https://github.com/rackspace/android-rackspacecloud
Stacktrace + source: http://pastebin.com/YkX7NvdD
Stacktrace:
// CRASH: com.rackspace.cloud.android (pid 3330)
// Short Msg: java.lang.NullPointerException
// Long Msg: java.lang.NullPointerException
// Build Label: google/takju/maguro:4.1.1/JRO03C/398337:user/release-keys
// Build Changelist: 398337
// Build Time: 1341437384000
// java.lang.NullPointerException
// at android.widget.Spinner$DialogPopup.dismiss(Spinner.java:828)
// at android.widget.Spinner$DialogPopup.onClick(Spinner.java:862)
// at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
// at android.widget.AdapterView.performItemClick(AdapterView.java:298)
// at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
// at android.widget.AbsListView.onKeyUp(AbsListView.java:2996)
// at android.widget.ListView.commonKey(ListView.java:2196)
// at android.widget.ListView.onKeyUp(ListView.java:2051)
// at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
// at android.view.View.dispatchKeyEvent(View.java:7086)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1354)
// at android.widget.ListView.dispatchKeyEvent(ListView.java:2026)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
// at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892)
// at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369)
// at android.app.Dialog.dispatchKeyEvent(Dialog.java:702)
// at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819)
// at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3575)
// at android.view.ViewRootImpl.deliverKeyEvent(ViewRootImpl.java:3531)
// at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3113)
// at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
// at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
// at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
// at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
// at android.os.MessageQueue.nativePollOnce(Native Method)
// at android.os.MessageQueue.next(MessageQueue.java:125)
// at android.os.Looper.loop(Looper.java:124)
// 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)
//
** Monkey aborted due to error.
Events injected: 5252
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=23 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=47382ms (0ms mobile, 47382ms wifi, 0ms not connected)
** System appears to have crashed at event 5252 of 10000 using seed 0

According to the code I am seeing at GrepCode, we have this :
public void dismiss() {
mPopup.dismiss();
mPopup = null;
}
So your NPE is caused by mPopup which is private AlertDialog of DialogPopup (private class of Spinner), probably the dialog to show the options of the spinner when you click it. mPopup is only set to something different from null at DialogPopup.show(). That method is called at Spinner.performClick(),i.e., when the spinner is clicked.
But then this is the weird part. The stack trace seem to be when an item of the mPopup was clicked, because DialogPopup is set as its OnClickListener. So at that point mPopup should not be null. But when DialogPopup.dismiss() it is null.
What can explain that? Here's my hypothesis. Well, monkey usually is pretty fast. Faster than actual users. It might be able to click two items before the mPopup was really dismissed by the first DialogPopup.onClick(). So we have two calls to DialogPopup.dismiss(), with the second cauing the NPE.
So here are my conclusions:
Because we are dealing only with internal classes and your code is not responsible for triggering the code that crashed, this is very likely an Android platform bug.
To fix this you must be able to reproduce and debug in eclipse in order to fully understand what is happening . You will need to download the Android platform code inorder to be able to step into the spinner code. Alternatively you can put log on the Spinner code and build Jelly Beans and flash your phone ( or replace the framework.jar)
If my hypothesis is correct, then debugging with ecplise won't help. You will need the logs to debug the problem. But if my hypothesis is right, then we think we should not worry. Normal user will hardly be able to click so fast.
You could advice the Android guys to do a if-null check. But only after you found the real root cause. Otherwise , you will be maskig the problem

Related

NFC service dead android.os.DeadObjectException

We are working on NFC tag android app and it is working properly 50% of times, and rest of the times we get NFC service dead exception in below try blocks:
Scenario is we connect to nfc Tag first time and send data, it always works fine.
Then we don't move phone away and after 1-2 seconds we again tries to connect to nfc tag(if not connected) to send data and 30% of times we get NFC service dead exception and it doesn't start until we disable and enable mobile's NFC.
Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY
+ Process.THREAD_PRIORITY_MORE_FAVORABLE); //first line of doInBackground()
if(((ArrayList<Byte>) params[0]).size()<=0){
return "No image selected!";
}
NfcA nfcaTag = (NfcA) params[2];
try{
nfcaTag = NfcA.get(tag);
if (!nfcaTag.isConnected()){
nfcaTag.connect(); //this is line 175 MainActivity
}
try {
nfcaTag.close();
}
Exception:
NFC service dead
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:622)
at android.nfc.INfcTag$Stub$Proxy.connect(INfcTag.java:285)
at android.nfc.tech.BasicTagTechnology.connect(BasicTagTechnology.java:73)
at android.nfc.tech.NfcA.connect(NfcA.java)
at de.silab.nfc.vistagnfcappv1.MainActivity$2.onClick(MainActivity.java:175)
at android.view.View.performClick(View.java:5723)
at android.view.View$PerformClick.run(View.java:22689)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6361)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Is there any way to solve this issue. We are stuck here since long time.
And any way to restart NFCAdapter/ nfc service by catching this exception?
Your nfcaTag's hosting process is dead. It has been close()'d. Your first step should be to debug by logging info to the console about your variables to see if something is unusual.
I find it strange that you close() your nfcaTag immediately after connect()'ing it. Maybe these two statements conflict?
Also, consider why you have initialized the nfcaTag only to change it immediately in the next try statement.
Is your NfcA.get(tag) occasionally returning a null NfcA object? Is tag occasionally null? You need to test every variable, especially the ones you haven't shared here completely in your question.

SIGSEGV error with QtThread on deleting QSGNode

I am working on a Qt app which runs on android & iOS.
Scenario:
Calling delete on a pointer causes my app to crash sometimes gives me the following error on Android.
Fatal signal 11 (SIGSEGV), code 1, fault addr 0x3c in tid 7134 (QtThread)
This is caused due to a delete call in updatePaintNode of my QQuickItem derived class.
// My updatePaintNode logic relevant to this question
QSGNode * MyQQuickItem::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) {
Q_UNUSED(oldNode)
Q_UNUSED(updatePaintNodeData)
if(class_mem_node != Q_NULLPTR) {
delete class_mem_node; // this is where the crash occurs
}
class_mem_node = new QSGNode;
// Execute drawing logic
return class_mem_node;
}
Problem:
Another window of my application is dependent on MyQQuickItem::updatePaintNode to execute but sometimes on Android the call to delete class_mem_node causes the crash with the Fatal signal error. Interestingly, the issue only happens on android, not on iOS or OSX.
Question:
What is wrong in my logic in updatePaintNode ? Is this a thread synchronisation issue?
Is there some way I can check whether the QSGNode is in use & return out?
When you return class_mem_node; you don't have ownership of the class_mem_node any more.
The implementation may delete the node when it becomes not useful. It then passes nullptr as oldNode on the next call to the updatePaintNode().
Don't store class_mem_node, use oldNode.

Race condition between Application onCreate and resources loaded?

I have the following application class for my app. When the application starts, I want to get some settings from preferences and start a background service.
public class MyApplication extends Application {
public void onCreate() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String key = getResources().getString(R.string.prefkey_updateinterval);
...
}
This normally works fine, but occasionally when starting my program from eclipse "Run" I get this error:
10-10 08:25:47.016: E/AndroidRuntime(26402): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0a0004
10-10 08:25:47.016: E/AndroidRuntime(26402): at android.content.res.Resources.getText(Resources.java:216)
10-10 08:25:47.016: E/AndroidRuntime(26402): at android.content.res.Resources.getString(Resources.java:269)
10-10 08:25:47.016: E/AndroidRuntime(26402): at com.karwosts.MyApp.PortfolioStore.onCreate(PortfolioStore.java:40)
10-10 08:25:47.016: E/AndroidRuntime(26402): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
10-10 08:25:47.016: E/AndroidRuntime(26402): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3395)
This id is from my R.java:
public static final int prefkey_updateinterval=0x7f0a0004;
Since this works fine most of the time, I have to assume that there is some kind of race condition between onCreate and the resources being loaded?
If that's the case, is it recommended not to read resources in Application onCreate?
If so, is there a better place to initialize a service when application launches?
Since this works fine most of the time, I have to assume that there is some kind of race condition between onCreate and the resources being loaded?
If the same APK file -- no recompile, no reinstall, etc. -- does not consistently generate the error, then it might be some sort of race condition, though that would surprise me.
If the same APK file consistently fails, then this is a more garden-variety resources-out-of-sync-with-the-rest-of-the-code problem, and cleaning the project will clear it up.
is there a better place to initialize a service when application launches?
IMHO, the number of apps that need to "initialize a service when application launches" is extremely low, to the point where I cannot think of a scenario off the cuff where this would be a good plan. That's not to say that you do not have such a scenario, but it's a serious code smell in my book without an explanation.
I've noticed that in cases where a lot of resources are used (and generated in R.java), cleaning the application before running fixes these issues. So I would assume this is not a race condition - but an issue with Eclipse or the Android SDK with not refreshing resources. As for the placement of the code - it's is as good as any other option, in my opinion.

Android sometimes I get android.app.RemoteServiceException: Bad notification posted from package. Why?

I have a serius problem with my notification.
Sometimes when my app post the same custom notification I get this error:
android.app.RemoteServiceException: Bad notification posted from package com.packagename: Couldn't expand RemoteViews for: ClassName(package=com.packagename id=0 tag=null notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x22))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1093)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3906)
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:840)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
at dalvik.system.NativeStart.main(Native Method)
What I have to do?
The notification contains only LinearLayout, TextViews and ImageViews and it works perfect most of the time.
There is a way to surround this error with try/catch so in this way android not stop my app?
Many thanks...
1) http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/app/ActivityThread.java#ActivityThread
From here we can see that this error can arise only in the one case:
case SCHEDULE_CRASH:
throw new RemoteServiceException((String)msg.obj);
2)http://openstorage.gunadarma.ac.id/android/sdk/sdk_310712/sources/android-15/android/app/ApplicationThreadNative.java
case SCHEDULE_CRASH_TRANSACTION:
{
data.enforceInterface(IApplicationThread.descriptor);
String msg = data.readString();
scheduleCrash(msg);
return true;
}
So this error arises from the ApplicationThreadNative
You can try to track ahead and maybe you will find the cause of this error.

Error in android tetris - getEntry

At the time me and a friend are programming the classic game Tetris, for a school project. I have been programming for an while now and had implemented both a rotate and a moveBlock, and newBlock, draw, etc., methods, so I thought now maybe would be the perfect time to run it for the first time. But then i get the error msg:
11-11 21:27:41.877: WARN/ResourceType(473): getEntry failing because entryIndex 7 is beyond type entryCount 7
11-11 21:27:41.877: WARN/ResourceType(473): Failure getting entry for 0x7f060007 (t=5 e=7) in package 0: 0x80000001
11-11 21:27:51.697: WARN/ActivityManager(59): Launch timeout has expired, giving up wake lock!
11-11 21:27:51.697: WARN/ActivityManager(59): Activity idle timeout for HistoryRecord{45009538 com.prosjekt.tetris2/.TetrisandroidGameActivity}
I'm running it with a Thread that uses a self built View (surfaceHolder/surfaceView), with methods, basically I'm following an lesson that the teacher has, where she programmed a snake game. So with updating of the methods so they are correct with tetris it should work, but now I can't see the error. Anyone know what the error message means, just paste questions if more info needed.
I have added a lot of LOG commands and I just got LOG from the TetrisView (surfaceView) constructor and from the constructor in the Thread, so it's never inside any of the methods.

Categories

Resources