Android异步任务组关闭

时间:2014-03-20 06:20:19

标签: android android-intent background task

您好我正在使用android。我创建了一个带有异步任务的应用程序,其中一些进程在后台运行。我可以从服务器数据库中获取异步任务中的字符串值,现在我想将它与getStringExtra值进行比较传递intent.But当我使用代码我可以从数据库和Intent获取字符串,但它强制关闭,错误显示空指针异常无法启动activity.Is有任何可能的方法来获取OnPostExecute以外的字符串吗?

我使用了代码

   AsyncTask < Void, Void, Void > t = new AsyncTask < Void, Void, Void > () {

       @Override
       protected Void doInBackground(Void...arg0) {

           something code here
           return null;

       }



       @Override
       protected void onPostExecute(Void result) {
           Log.d("postexe", "p execute");
           StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

           StrictMode.setThreadPolicy(policy);
           try {

               HttpClient httpclient = new DefaultHttpClient();
               HttpPost httppost = new HttpPost("http://10.0.2.2:80/contactcheck.php");

               HttpResponse response1 = httpclient.execute(httppost);
               HttpEntity entity = response1.getEntity();
               is = entity.getContent();

               Log.e("log_tag", "connection success ");

           } catch (Exception e) {
               Log.e("log_tag", "Error in http connection " + e.toString());


           }
           try {
               BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
               StringBuilder sb = new StringBuilder();
               String line = null;

               while ((line = reader.readLine()) != null) {
                   sb.append(line + "\n");

               }
               is.close();

               result2 = sb.toString();

           } catch (Exception e) {
               Log.e("log_tag", "Error converting result " + e.toString());


           }
           try {
               JSONArray jArray = new JSONArray(result2);

               Log.w("Lengh", "" + jArray.length());
               for (int i = 0; i < jArray.length(); i++) {


                   JSONObject json_data = jArray.getJSONObject(i);

                   App_id = json_data.getString("app_id");
                   Log.i("hoiii", App_id);
                   String key = getIntent().getStringExtra("key");


                   if (getIntent().hasExtra("key")) {

                       if (key.equals(App_id)) {
                           setContentView(R.layout.home);

                           flag = 1;
                       }

                   } else {
                       finish();
                   }



               }
           } catch (JSONException e) {
               Log.e("log_tag", "Error parsing data " + e.toString());

           }

       }


   };


   t.execute();

所以我认为我在这里使用的setcontentView有问题。请帮我找出错误。谢谢提前

0 个答案:

没有答案