NullPointerException in handleStopActivity -- No reference to my code in stack trace - java

I'm a bit at a loss, here. I've been seeing a steadily increasing number of these NullPointerExceptions in handleStopActivity. I suspect that the increase coinicides with the increase in 2.2 upgrades to Droid owners, though that's just a guess. I've never seen the crash myself, and the stack trace provided by the market does not mention any of the classes I've written. As such, I have no idea where to start in fixing the problem.
java.lang.NullPointerException
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3674)
at android.app.ActivityThread.access$2600(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Since I don't know the cause, I also don't know what information to provide to aid in diagnosis, so I'll give an overiew:
My app is WootWatcher. It tracks Woot.com and notifies users of new items for sale. It does this by means of a service that runs in a separate process. The service and the main activity communicate with each other via aidl interface and callback. I also make use of message handlers in both the service and activity, and frequently spawn threads for expensive tasks.

Looking back at this 4-year old question, I realize I should be able to diagnose it, but unfortunately I can't find any version of AOSP for which these lines match up. The Droid must have used some altered version of the source that wasn't made available.
That said, Froyo's handleStopActivity() doesn't have many opportunities for a null pointer exception. The most likely one would point to Activity.finish() when the Activity has already been stopped, or is in the process of being stopped.
This usually happens when you register listeners that eventually call finish() and you don't unregister those listeners in onPause().

How about reporting a bug to Android Project (would mandate checking if anyone else reported it) ? If no code from You is in the stack trace, that would signal a bug in the framework. Although maybe in your other code You break e.g. an unspoken contract/assumption.

Refer the answer in this question. Looks like a known problem and has a solution too.
Hope it helps...
NullPointerException on onSaveInstanceState with AndroidFragments

I don't know, if you're still looking for a solution, but here's what I found out. If you have found a real solution, please let me know.
I just had the same issue.. I never had that problem and without changing code, it appeared for some reason. By using google, I found the question that Joseph posted, but that doesn't seem to be exactly the same. I also found this and this. These two seem to have the same issue, but no solution.. Then I found this blog.
The author tells something about what it's from - a bug in Android. Further, it has to do with a Cursor. That didn't fix my issue, but I noticed, that I used a Cursor, a few lines before calling startActivity(someIntent); (I also called finish(), but removing that line didn't make a difference).
I tried to remove the lines that include the Cursor and suddenly it works again..
I have no idea, why it works, but it does. I just moved the code with the Cursor to my other Activity.
It's definitly not a good solution, but it works for me.
There's just one more question: Do you even use a Cursor and call startActivity(..) or something similar?
Edit:
I just found out, that I didn't fix the problem, I just didn't test enough. The Activity I started was running fine until I wanted to create the next Activity out of that Activity I started before. On starting the next Activity, my App crashes again.

Maybe try wrapping the method handleStopActivity in try-catch block and handle the error yourself, giving yourself more details and preventing "force-close" ?

Related

New to Java profiling, i seem to have a problem with threads

I made a raycasting engine and it has some slowdowns. I never had to do profiling before, only step by step debug. I used JProfiler and from what i can understand the problem seem to be waiting/blocked threads. I dont know why this happens. If anyone could take a look at the code and give me some hints i would really appreciate. The code is in english but some comments are still in french (translation in progress). I've tried to make the code as explicit as possible but if there is something you are unsure of ill explain. Im not very familiar with how threads work but i believe everything related to them is in the "control" package. There are a lot of classes so instead of posting the code here ive put everything on github:
https://github.com/Thormind/Raycasting-engine.git
Here is an image of the threads profiling. Outside of that everything else (memory, cpu) seems fine.
Go to the call tree view, record CPU data and set the thread status selector to "Blocking", than you see in which call stacks the blocking occurs.
Detailed analysis of blocking situations is available in the "Monitors & Locks" view section.

How to detect cause of this crash from Crashlytics?

Suddenly my app started to crash enormously. I checked Crashlytics report but it doesn't tell me much. This is what it says, hopefully someone could give me a hint if had same/similar problem..
This seems to be related to a known jmDNS bug that was supposedly fixed a long time ago1:
https://sourceforge.net/p/jmdns/bugs/101/
https://sourceforge.net/p/jmdns/mailman/jmdns-discuss/thread/4EA5B242.4070003#gmail.com/
Apparently, the problem is triggered by lookup of malformed DNS names: see last email in discussion thread.
I suggest that you add some diagnostics to your app to find out what name your code is attempting to lookup.
1 - I have my doubts that it was actually fixed ... based on the discussion thread.

How to find forks in Activity Java code?

I have copy-pasted together MainActivity class for a simple Android application, which uses BluetoothAdapter, TextToSpeech, and also Runnable status checker, running periodically. For the latter, I have "implemented TextToSpeech.OnInitListener".
The code is probably too large to post here, so I will try to formulate the question in general form and then explain why.
How one is supposed to understand where "thread forks" happen in the Java code where everything looks like method invocations? Are there any conventions (for Android libraries specifically, of maybe it's Java-wide) to distinguish simple call from a call, which forks it's own thread? Or is the RTFM the only way to find where forking is happening?
And the actual problem is that Bluetooth LE scanning (?) sometimes duplicates, producing double (or triple, sometimes more) log entries one after another. I guess, I have a mistake somewhere in onStop, onResume, onDestroy, etc hooks (though I was trying to follow state transitions as on the diagram in the docs), but it is hard to find out why some threads/tasks survive and duplicate.
I am "programming" in Java only occasionally, so I have very little idea how concurrency could be debugged. But may be folks with experience can share general hints/advices/guidelines, useful in much more cases than mine.

Recurring Error in Eclipse "Could not delete '/some/file/in/war/dir' fix ..., then try refreshing..."

I have looked at the existing related posts here and although they do explain how to workaround the problem once it happens, I am trying to stop the problem from happening in the first place. I've tried to use sysinternals procmon to track down what's holding the lock on the file without success.
I would greatly appreciate any help in tracking down the actual cause of this recurring annoyance.
EDIT:
I'm not doing anything in particular to cause this, I'm just working as normal (which means autobuild and refreshes are happening) and a few times during the day, this will happen, necessitating use of the workarounds found elsewhere such as manually deleting the files and rebuilding

Android SDK not compiling apps correctly

It seems that the Android SDK doesn't compile my android app correctly. After building an app, I sometimes get seemingly random exceptions. The error goes away if I comment out the offending code, rebuild, uncomment the code, then rebuild again.
For instance, this code gave me a NullPointerException:
playButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivityForResult(settings, PLAY_GAME);
}
});
There is nothing wrong this code! Yet adb logcat tells me it's the cause of an exception.
Commenting out this code, rebuilding, uncommenting and rebuilding, makes the error go away.
What is going on?
This is making developing for android particularly frustrating.
Update: As I pointed out before, these are seemingly random errors that go away once I uncomment/recompile/comment/recompile. So I can't reproduce the stacktrace. It was a NullPointerException if I remember correctly.
However, if it is indeed buggy programming, why is the app running fine now w/o ANY errors at all?
Whenever I make a significant change to the app (add a new resource, a new class, function, etc), old code that was working fine breaks. Why?
Update: Seriously guys, lay off on the hate. I feel like a stumbled on a Atheists vs Christian debate. Sorry to have insunated that android was at fault. Started a new question with the latest errors:
App Ran Fine, Now Breaking for Seemingly Unknown Reasons
Commenting out this code, rebuilding, uncommenting and rebuilding, makes the error go away.
This might seem to you like a bug in Android, but I suspect that the real problem is a threading / synchronization related bug in your code. For instance, playButton may be being used before it is initialized.
But we cannot really help you unless you show us the stack trace and identify the line(s) of code where the exception was thrown.
However, if it is indeed buggy programming, why is the app running fine now w/o ANY errors at all?
See above: it is most likely because you have a threading / synchronization issue. You need to be aware that different parts of an application with a GUI will run in different threads ... even if you didn't explicitly create those threads. There are rules you have to follow. If you don't follow those rules, bad things happen ... like exceptions that sometimes happen and sometimes don't happen, depending on which way the wind is blowing.
Could be that your PLAY_GAME activity is returning without a result, e.g., if you press the back button & it just stops without calling setResult().
No, as noted in several other places, sometimes the source and the bin get out of sync. I've noticed numerous times, specially when making changes to XML. The solution, for commandline users, is to remove the bin directory, and re-compile. Problem goes away.

Categories