In my android app I am using AsyncTask. It was working perfectly but from last 2 days my app crashed when I called .execute() of AsyncTask. The error is:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.os.AsyncTask.execute(AsyncTask.java:378)
at com.riksof.a320.remote.RemoteObject.update(RemoteObject.java:117)
at com.fitmo.controller.activity.FitmoEditActivityDetailController.updateActivityDate(FitmoEditActivityDetailController.java:64)
at com.fitmo.controller.activity.FitmoEditActivityDetailController.access$0(FitmoEditActivityDetailController.java:51)
at com.fitmo.controller.activity.FitmoEditActivityDetailController$1.onClick(FitmoEditActivityDetailController.java:45)
at android.view.View.performClick(View.java:2532)
at android.view.View$PerformClick.run(View.java:9293)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4263)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
When I saw the code inside AsyncTask.java, I found this code inside AsyncTask constructor:
switch (mStatus)
So I debug the AsyncTask status by calling getStatus() method of AsyncTask before calling execute() and the value is null here as well. What can be the reason for this any ideas ?
I am not getting this every time. Some times it works properly sometimes it doesn't.
Did you remove the AsyncTask myTask = new AsyncTask() by accident?
Related
I have ocassional crash at my emulator, but for now never on tablet on which I am testing.
java.util.ConcurrentModificationException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:346)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:375)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:373)
at java.util.HashMap.writeObject(HashMap.java:1024)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1229)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1215)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:1153)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:420)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1251)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1587)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1859)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1701)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1665)
at android.os.Parcel.writeSerializable(Parcel.java:1155)
at android.os.Parcel.writeValue(Parcel.java:1114)
at android.os.Parcel.writeMapInternal(Parcel.java:479)
at android.os.Bundle.writeToParcel(Bundle.java:1552)
at android.os.Parcel.writeBundle(Parcel.java:493)
at android.app.ActivityManagerProxy.activityPaused(ActivityManagerNative.java:1574)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3292)
at android.app.ActivityThread.access$2500(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
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)
It seems from the log it happens when the activity is going to pause.
All my activity are accessing a common super class static object (global data), which indeed has some linkedhashmap inside, and I am saving this globaldata with putSerializable inside onSaveInstanceState. I have tried to put save/restore of globaldata inside my base activity class inside sattic synchronized methods, but it didn't helped.
My I know from yours experiences if this is some internal android bug (maybe just emulator bug) or If I am managing saving of global data (which has LinkedHashMap inside) wrong. Or is there another way to share common data between activites?
Thanks
I've been getting this error in my developer portal. I'm not sure why. Stack trace tracks back into some internal function call inside WebView object.
java.lang.NullPointerException
at android.webkit.WebView.loadUrlImpl(WebView.java:3008)
at android.webkit.WebView.loadUrlImpl(WebView.java:3047)
at android.webkit.WebView.loadUrl(WebView.java:3040)
at com.myapp.android.PreviewActivity.notifyJS(PreviewActivity.java:175)
at com.myapp.android.PreviewActivity.access$14(PreviewActivity.java:174)
at com.myapp.android.PreviewActivity$ActionBarItemClickListener.onClick(PreviewActivity.java:901)
at android.view.View.performClick(View.java:3644)
at android.view.View$PerformClick.run(View.java:14313)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
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:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
In my code at com.myapp.android.PreviewActivity.notifyJS(PreviewActivity.java:175), there is this line
webView.loadUrl("javascript:MyApp.onClick('" + action + "');");
I'm actually invoking a javascript call from my java code. Has anyone faced this issue before?
I found the answer myself. If webView.destroy() has already been called then calling webView.loadUrl() will cause this exception.
It seems that your webview is null. Did you call findView before?
The code: http://pastebin.com/5bhKULGd
the problem:
When you click an item in the gridview, OCLGenre (OnItemClickListener for Genre view)
fires an nullPointer at line 123. I'm trying to understand where the nullPointer comes from but can't find it.
The stack:
ERROR/AndroidRuntime(10511): FATAL EXCEPTION: main
java.lang.NullPointerException
at com.MMWeb.MMWeb$browse$1.onItemClick(MMWeb.java:123)
at android.widget.AdapterView.performItemClick(AdapterView.java:284)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Anyone got a pointer to where to find the source of this nullPointer?
If you try to access an object which is null. Like the below example.
ClassA objA;
At this time you have just declared this object but you have not initialized or instantiated it.
When you try to access any property or method in it, it will throw
NullPointerException.
Oke i found my problem By moving the ImageAdapter out of the "browse" class, the "browse" class did not have any reference to the ArrayList 'items'. I could find the problem because, after all, i defined the ArrayList at line 112. However, showGenres() uses a local ArrayList, and the ImageAdapter would put it in "browser.items". Fixed it by removing the local decleration of items on line 145, 154 and 162
I am getting a crash report back that says OutOfMemoryError in my call to startManagingCursor. Here is the returned stack trace:
java.lang.OutOfMemoryError
at java.util.ArrayList.add(ArrayList.java:123)
at android.app.Activity.startManagingCursor(Activity.java:1652)
at com.bubblewaretechnology.pianounlockscreen.LockDetecter.onResume(LockDetecter.java:633)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.ActivityThread.performNewIntents(ActivityThread.java:1789)
at android.app.ActivityThread.handleNewIntent(ActivityThread.java:1795)
at android.app.ActivityThread.access$2300(ActivityThread.java:124)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1015)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3806)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
I am very careful to close my cursors, SQLiteDatabase and SQLiteOpenHelper. Here is a short code segment that the crash refers to:
Cursor callCursor = lockLib.getCallState();
startManagingCursor(callCursor);
....
callCursor.close();
Pretty stumped on how to go about troubleshooting this problem. I know startManagingCursor is depreciated but I am not targeting HONEYCOMB or later, so I cant switch to CursorLoader. Does anyone have any suggestions on how to proceed?
I know it's lame to answer your own question but you can remove startManagingCursor, Reference Link, as long as you are managing the lifecycle of your cursor appropriately.
I am getting the following stack trace (below is a complete copy) , this gives me little or no indication as to where in a massive application it is when going wrong and user feedback is nothing beyond "It crashed".
Is there anything I can do to pinpoint this more ?
java.lang.NullPointerException at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:291)
at android.widget.AdapterView.checkFocus(AdapterView.java:689)
at android.widget.AdapterView$AdapterDataSetObserver.onInvalidated(AdapterView.java:813)
at android.database.DataSetObservable.notifyInvalidated(DataSetObservable.java:43)
at android.widget.BaseAdapter.notifyDataSetInvalidated(BaseAdapter.java:54)
at android.widget.ArrayAdapter$ArrayFilter.publishResults(ArrayAdapter.java:469)
at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
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)
Look at the code for ArrayAdapter.getCount():
/**
* {#inheritDoc}
*/
public int getCount() {
return mObjects.size();
}
Clearly mObjects is null, i.e. your ListView or other AdapterView-derived type is trying to use the adapter before you've initialized it with it's data.
What you could do is putting debug information before every call to getCount() using the Log class
Log.d("tag", "Trying to get count on line 50 class Test");
then open logcat and find the last entry of this log before the error occures. Then you have the right location of the crash.