So this problem happens only some times. There is no rhyme or reason that I can see. I suspect, the faster the user moves around the app, the more likely it happens.
Here is LogCat:
02-20 12:09:58.526: E/AndroidRuntime(18777): FATAL EXCEPTION: main
02-20 12:09:58.526: E/AndroidRuntime(18777): java.lang.NullPointerException
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:128)
02-20 12:09:58.526: E/AndroidRuntime(18777): at com.---.---.ReviewAdapter.<init>(ReviewAdapter.java:42)
02-20 12:09:58.526: E/AndroidRuntime(18777): at com.---.---.RateFragmentActivity$ReviewFragment$ReviewTask.onPostExecute(RateFragmentActivity.java:1203)
02-20 12:09:58.526: E/AndroidRuntime(18777): at com.---.---.RateFragmentActivity$ReviewFragment$ReviewTask.onPostExecute(RateFragmentActivity.java:1)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.os.AsyncTask.finish(AsyncTask.java:631)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.os.AsyncTask.access$600(AsyncTask.java:177)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.os.Looper.loop(Looper.java:137)
02-20 12:09:58.526: E/AndroidRuntime(18777): at android.app.ActivityThread.main(ActivityThread.java:5193)
02-20 12:09:58.526: E/AndroidRuntime(18777): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 12:09:58.526: E/AndroidRuntime(18777): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 12:09:58.526: E/AndroidRuntime(18777): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
02-20 12:09:58.526: E/AndroidRuntime(18777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
02-20 12:09:58.526: E/AndroidRuntime(18777): at dalvik.system.NativeStart.main(Native Method)
The crash happens here:
adapter = new ReviewAdapter(getActivity(), r, tf);
r (an array) is not null, neither is tf, a TrueType font).
On the ReviewAdapter, here is other side of crash line 42:
public ReviewAdapter(Context context, Review[] objects, Typeface tf) {
super(context, 0, objects); // line 42
I believe context is null.
Here is the big picture:
I have a FragmentActivity with a Fragment and ListFragment. The adapter is inside the ListFragment of course. Neither of those fragments interact with each other. they are statically displayed in the xml.
So ReviewAdapter is called inside:
protected void onPostExecute(Void v) {
inside of:
public class ReviewTask extends AsyncTask<String, String, Void> {
inside of:
public static class ReviewFragment extends ListFragment {
inside of:
public class RateFragmentActivity extends SherlockFragmentActivity implements
ActionBar.TabListener {
That is the context of things. I must not be handling my fragment lifecycle correctly, but this error is so sporadic.
Last note: I do have this in my manifest:
android:configChanges="orientation|screenSize|keyboardHidden"
So config changes are not causing this.
Someone please help me on this: this problem has plagued me for months. If you need more code to view, by all means, let me know were and I will provide!
Contextisnullif the exception is at that line. You should testgetActivity()for returningnull. Do you save that task across a configuration change?null. (so kind of like what you said). It seems I just put a band aid in the real issue though. I also removed this:android:configChanges="orientation|screenSize|keyboardHidden"As I want layouts to be able to change based on port/land. So no to your second questions?