运行时异常Android

时间:2013-04-08 07:41:46

标签: android


我在我的应用程序中遇到一个奇怪的错误,我在下面的代码中得到NULL异常,有时候(有时候是的,听起来很奇怪!!!)

请看看

String appId = preferences.getString(ProjectConstants.IMEI_NO, null);
    if (appId == null) {
        // Here i am getting exception:
        TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
        appId = manager.getDeviceId();
        preferences.edit().putString(ProjectConstants.IMEI_NO, appId);
    }

Logcat

    java.lang.RuntimeException: An error occured while executing doInBackground()
 at android.os.AsyncTask$3.done(AsyncTask.java:278)
 at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
 at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
 at java.util.concurrent.FutureTask.run(FutureTask.java:137)
 at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
 at java.lang.Thread.run(Thread.java:856) Caused by: java.lang.NullPointerException
 at com.homeshop18.service.GSONfunctions.getGSONfromURL(GSONfunctions.java:115)
 at com.homeshop18.ui.myorder.MyOrdersFragment$DownloadMyOrders.doInBackground(MyOrdersFragment.java:92)
 at com.homeshop18.ui.myorder.MyOrdersFragment$DownloadMyOrders.doInBackground(MyOrdersFragment.java:1)
 at android.os.AsyncTask$2.call(AsyncTask.java:264)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) ... 5 more

任何帮助将不胜感激..:D

1 个答案:

答案 0 :(得分:0)

您的logcat日志清楚地显示,

  

在   com.homeshop18.service.GSONfunctions.getGSONfromURL(GSONfunctions.java:115)

请在第115行检查,有空的东西,你正试图访问它的财产。

更新,如果您的第一个代码段来自GSONfunctions,则必须检查context是否为空。