2012-07-11 235 views
0

我有一個致命的異常:AsyncTask#1在下面的部分,但不知道爲什麼。致命的異常:AsyncTask#1

/** 
    * getting Charts from URL 
    * */ 
    protected String doInBackground(String... args) { 
     // Building Parameters 
     ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); 
     // getting JSON string from URL 
     JSONObject json = jParser.makeHttpRequest(url_read, "POST", params); 

     // Check your log cat for JSON response 
     Log.d("Charts: ", json.toString()); 

     try { 
      // Checking for SUCCESS TAG 
      int success = json.getInt(TAG_SUCCESS); 

      if (success == 1) { 
       // products found 
       // Getting Array of Products 

       JSONArray charts = json.getJSONArray(TAG_CHARTS); 

       // looping through All Products 
       for(int i=0;i<charts.length();i++) { 
        JSONObject json_data = charts.getJSONObject(i); 

        String id = json_data.getString("id"); 
        String interpret = json_data.getString("interpret"); 
        String titel = json_data.getString("titel"); 
        String album = json_data.getString("album"); 
        String albumcover = json_data.getString("albumcover"); 
        String likes = json_data.getString("likes"); 

        HashMap<String, String> map = new HashMap<String, String>(); 

        map.put(TAG_ID, id); 
        map.put(TAG_INTERPRET, interpret); 
        map.put(TAG_TITEL, titel); 
        map.put(TAG_ALBUM, album); 
        map.put(TAG_ALBUMCOVER, albumcover); 
        map.put(TAG_LIKES, likes);  

        songslist.add(map); 

       } 
      } else { 
       // no products found 
       // Launch Add New product Activity 
       Intent i = new Intent(getApplicationContext(), 
         CreateSong.class); 
       // Closing all previous activities 
       i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(i); 
      } 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 

這是我的第一個問題。希望你知道該怎麼做。我從數據庫獲取數據並將它們放入一個JSON數組中,然後放入一個HashMap中,但似乎錯誤是由JSON引起的。

編輯:LOG CAT

07-11 23:20:48.320: D/CLIPBOARD(13241): Hide Clipboard dialog at Starting input: finished by someone else... ! 
07-11 23:20:52.510: D/dalvikvm(13241): GC_FOR_ALLOC freed 139K, 3% free 9004K/9223K, paused 13ms 
07-11 23:20:52.650: E/JSON Parser(13241): Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject 
07-11 23:20:52.650: W/dalvikvm(13241): threadid=11: thread exiting with uncaught exception (group=0x40c331f8) 
07-11 23:20:52.675: E/AndroidRuntime(13241): FATAL EXCEPTION: AsyncTask #1 
07-11 23:20:52.675: E/AndroidRuntime(13241): java.lang.RuntimeException: An error occured while executing doInBackground() 
07-11 23:20:52.675: E/AndroidRuntime(13241): at android.os.AsyncTask$3.done(AsyncTask.java:278) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.lang.Thread.run(Thread.java:856) 
07-11 23:20:52.675: E/AndroidRuntime(13241): Caused by: java.lang.NullPointerException 
07-11 23:20:52.675: E/AndroidRuntime(13241): at de.andreasgloeckner.ShowCharts$LoadAllProducts.doInBackground(ShowCharts.java:172) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at  de.andreasgloeckner.ShowCharts$LoadAllProducts.doInBackground(ShowCharts.java:1) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at android.os.AsyncTask$2.call(AsyncTask.java:264) 
07-11 23:20:52.675: E/AndroidRuntime(13241): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
07-11 23:20:52.675: E/AndroidRuntime(13241): ... 4 more 
+0

您需要共享異常堆棧跟蹤和來自logcat的輸出。這是權威:)。其他一切都是猜測。 – Anirudh 2012-07-11 21:10:51

+0

Srsly,我有這個網站的一些問題...什麼是最好的可能性添加日誌貓?當我編輯我的帖子時,它看起來很奇怪,正如你所看到的。 – Andy 2012-07-11 21:27:06

回答

0

你在你的代碼(ShowCharts.java,線172)有一個NullPointerException異常。現在弄清楚哪一行是。您顯然正在訪問一個空對象,或者只是在這裏共享172行。它可能是songslist對象。我在您分享的代碼塊中看不到初始化。

Caused by: java.lang.NullPointerException 
    07-11 23:20:52.675: E/AndroidRuntime(13241): at de.andreasgloeckner.ShowCharts$LoadAllProducts.doInBackground(ShowCharts.java:172) 
+0

我已經修復了它;)我的php文件中有一個錯誤。 – Andy 2012-07-13 12:59:46

0

從doInBackground方法中,你不能改變或接觸任何UI元素,所以你不能調用其他活動,你所要做的就是從onPostExecute方法內從您的AsyncTask

調用另一個活動
相關問題