AsyncTask 空指针错误, 新手求教

04-08 23:15:21.478: E/BaseActivity(1456): BaseActivity.class :: onCreate()

04-08 23:15:21.488: I/LoginActivity(1456): LoginActivity.class :: onCreate()

04-08 23:15:22.248: E/HttpRequest(1456): Request Url :: http://192.168.1.101:8026/login

04-08 23:15:22.248: E/HttpRequest(1456): Parameters' HashMap :: {password=admin, username=admin}

04-08 23:15:22.538: E/HttpRequest(1456): StatusCode = 200

04-08 23:15:22.548: E/HttpRequest(1456): {"response":"login","userinfo":{"uid":0,"uname":"admin","upass":""}}

04-08 23:15:22.568: E/BaseActivity(1456): Request complete successfully

04-08 23:15:22.998: I/dalvikvm-heap(1456): Grow heap (frag case) to 23.853MB for 6554896-byte allocation

04-08 23:15:23.078: I/dalvikvm(1456): Could not find method android.content.Context.getExternalFilesDirs, referenced from method com.baidu.mapapi.utils.e.c

04-08 23:15:23.078: W/dalvikvm(1456): VFY: unable to resolve virtual method 268: Landroid/content/Context;.getExternalFilesDirs (Ljava/lang/String;)[Ljava/io/File;
04-08 23:15:23.398: I/System.out(1456): admin
04-08 23:15:23.438: I/Choreographer(1456): Skipped 31 frames! The application may be doing too much work on its main thread.
04-08 23:15:41.668: W/dalvikvm(1456): threadid=1: thread exiting with uncaught exception (group=0x4184a898)
04-08 23:15:41.668: E/AndroidRuntime(1456): FATAL EXCEPTION: main

04-08 23:15:41.668: E/AndroidRuntime(1456): java.lang.NullPointerException
04-08 23:15:41.668: E/AndroidRuntime(1456): at com.zwu.navi.BasetoActivity$AT.onPreExecute(BasetoActivity.java:439)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.AsyncTask.execute(AsyncTask.java:534)

04-08 23:15:41.668: E/AndroidRuntime(1456): at com.zwu.navi.BasetoActivity$3.onClick(BasetoActivity.java:190)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.view.View.performClick(View.java:4476)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.view.View$PerformClick.run(View.java:18799)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.Handler.handleCallback(Handler.java:730)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.Handler.dispatchMessage(Handler.java:92)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.os.Looper.loop(Looper.java:177)

04-08 23:15:41.668: E/AndroidRuntime(1456): at android.app.ActivityThread.main(ActivityThread.java:5493)

04-08 23:15:41.668: E/AndroidRuntime(1456): at java.lang.reflect.Method.invokeNative(Native Method)

04-08 23:15:41.668: E/AndroidRuntime(1456): at java.lang.reflect.Method.invoke(Method.java:525)

04-08 23:15:41.668: E/AndroidRuntime(1456): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)

04-08 23:15:41.668: E/AndroidRuntime(1456): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)

04-08 23:15:41.668: E/AndroidRuntime(1456): at dalvik.system.NativeStart.main(Native Method)
04-08 23:16:02.548: I/Process(2064): Sending signal. PID: 2064 SIG: 9

System.out.println(getIntent().getStringExtra("test"));有数据
new AT().execute(getIntent().getStringExtra("test"));出现错误

4个回答

没有getExternalFilesDirs这个方法,应该是android系统版本太早了,这个方法是后期版本才有的,应该是android4.4。如果早期的版本是没有这个方法的。

danielinbiti
danielinbiti 回复pigspring2008: 看AT.onPreExecute的代码
5 年多之前 回复
pigspring2008
pigspring2008 我是新手,,System.out.println(getIntent().getStringExtra("test")); 里面已经有数据了,为什么还是提示空指针错误呢?
5 年多之前 回复

看BasetoActivity.java文件的439行,断点调试,看看谁是null值

AsyncTask我记得有2个函数,这2个函数android虚拟机分别用2个线程先后执行,并且是是2个实例,要注意

楼主贴报错的代码片段上来吧

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问