-3

有时我在我的应用程序中遇到此崩溃错误当我多次单击按钮时,它会崩溃,按钮是向服务器发送 SOAP 请求,完整的 logcat 如下:</p>

E/AndroidRuntime(16290): FATAL EXCEPTION: AsyncTask #1
06-06 15:17:16.003: E/AndroidRuntime(16290): java.lang.RuntimeException: An error occured while executing doInBackground()
06-06 15:17:16.003: E/AndroidRuntime(16290):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at enter code herejava.lang.Thread.run(Thread.java:1027)
06-06 15:17:16.003: E/AndroidRuntime(16290): Caused by: java.lang.NullPointerException
06-06 15:17:16.003: E/AndroidRuntime(16290):    at com.bgi.genebook.task.QueryCalAllDataTask.doInBackground(QueryCalAllDataTask.java:24)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at com.bgi.genebook.task.QueryCalAllDataTask.doInBackground(QueryCalAllDataTask.java:1)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-06 15:17:16.003: E/AndroidRuntime(16290):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
06-06 15:17:16.003: E/AndroidRuntime(16290):    ... 4 more

点击按钮将运行代码:

Map<String, Object> mapSyc = new HashMap<String, Object>();
mapSyc.clear();
QueryCalAllDataTask<VipOxygen> task = new QueryCalAllDataTask<VipOxygen>(
                this);
mapSyc.put("date", date);
mapSyc.put("wsdl", VipBloodOxygenWebService.wsdl);
task.execute(mapSyc);

QueryCalAllDataTask.java 是:

public class QueryCalAllDataTask<T> extends
        AsyncTask<Map<String, Object>, Integer, List<Map<String, String>>> {
    GBListener<T> listener;

    public QueryCalAllDataTask(GBListener<T> listener) {
        this.listener = listener;
    }

    @Override
    protected synchronized List<Map<String, String>> doInBackground(Map<String, Object>... params) {
        List<Map<String, String>> contentListDay = new ArrayList<Map<String, String>>();
        Log.e("OPERATE", params[0].get("wsdl").toString()); // line 24
        try{
        contentListDay = (List<Map<String, String>>)BaseWebService.getDataAllDaysCountOfMouth(params[0]
                .get("wsdl").toString(), params[0].get("date").toString());
        }catch(Exception e){

        }
        return contentListDay;
    }

    @Override
    protected void onPostExecute(List<Map<String, String>> list) {
        System.out.println("QueryTask.onPostExecute()" + list);
        listener.getAllCalData(list);
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        System.out.println(values);
    }

}

谁能帮助我?为什么?当我多次单击该按钮时,此崩溃偶尔会出现一次!

4

2 回答 2

1

错误肯定在这里:

contentListDay = (List<Map<String, String>>)BaseWebService.
getDataAllDaysCountOfMouth(params[0].get("wsdl").toString(),  
params[0].get("date").toString());

我不知道get("wsdl")andget("date")中的哪一个返回 null,无论如何,你永远不应该在不知道对象是否存在或它是null.

在打电话之前,toString(),你应该检查一下。就像是:

 something = params[0].get("wsdl");

 if (something==null)
     System.out.println("Can't get parameter wsdl");
 else
     something.toString();

对参数执行相同的date操作,您将能够知道那里返回 null 的内容,并修复它。

于 2013-06-06T07:56:02.043 回答
0

您的代码中可能导致NPE异常的可能操作是 this params[0].get("wsdl").toString()

这意味着,您的第一个参数(带有 index 0)没有wsdl键入它。

于 2013-06-06T07:56:17.293 回答