2015-11-01 103 views
0

我有兩個活動 1.列表視圖(多個項目與標題和鏈接) 2.文本視圖(當點擊列表視圖中的任何項目時,獲取鏈接,做xml解析並獲取內容並顯示)應用程序沒有運行之間切換活動

我用意圖從列表視圖切換到文本視圖活動。現在,在第一次點擊時,它將啓動文本查看活動。在按下設備上的按鈕後,它又回到列表視圖。 Uptil現在沒事了。

主要問題是,當第二次,我點擊列表視圖中的任何項目,Android應用程序給我錯誤「不幸的應用程序已停止」。 並點擊「確定」後,顯示第二項內容。而當第二次,我按下後退按鈕,應用得到了關閉

這裏是我的第二個活動

public class ColoumnView extends Activity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_coloumn_view); 
    Intent intent = getIntent(); 
    String message = intent.getStringExtra(MainListActivity.EXTRA_MESSAGE); 
    TextView myColoumnView = (TextView)findViewById(R.id.ColoumnView); 
    myColoumnView.setText(message); 
} 
@Override 
public void onBackPressed() 
{ 
    // code here to show dialog 
    super.onBackPressed(); 
    finish(); 
} 

這是我的第一個活動的地方創造一個意圖

protected void onPostExecute(List<ContentGetter.Content> contents) { 
     if (contents != null && mException == null) { 
      for(int i=0; i<contents.size();i++) { 
       if(contents.get(i).summary != null) 
       { 
        summaryContent= contents.get(i).summary; 
       } 
       else { 
        continue; 
       } 
       Intent intent = new Intent(MainListActivity.this,ColoumnView.class); 
       intent.putExtra(EXTRA_MESSAGE, summaryContent); 
       startActivity(intent); 
       Log.d(TAG, contents.get(i).summary != null ? contents.get(0).summary : "NULL"); 
      } 

     } else { 
      if (mException instanceof IOException){ 
      } else if (mException instanceof XmlPullParserException) { 
      } 
     } 


    } 

部分編輯:這是崩潰日誌

11-01 13:11:46.274 2296-2296/com.example.talha.appforblog E/AndroidRuntime﹕ FATAL EXCEPTION: main 
Process: com.example.talha.appforblog, PID: 2296 
java.lang.NullPointerException: println needs a message 
     at android.util.Log.println_native(Native Method) 
     at android.util.Log.d(Log.java:139) 
     at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.onPostExecute(MainListActivity.java:241) 
     at com.example.talha.appforblog.MainListActivity$DownloadXmlTaskContent.onPostExecute(MainListActivity.java:206) 
     at android.os.AsyncTask.finish(AsyncTask.java:632) 
     at android.os.AsyncTask.access$600(AsyncTask.java:177) 
     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:135) 
     at android.app.ActivityThread.main(ActivityThread.java:5221) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
+0

你可以發佈崩潰日誌,當空ptr異常來 – pvn

+0

請檢查,我編輯了 – user3585510

+0

替換** Log.d(TAG,contents.get(i).summary!= null?contents.get(0 ).summary:「NULL」); ** with ** Log.d(TAG,contents.get(i).summary!= null?contents.get(i).summary:「NULL」); ** –

回答

1

問題是在活動M的第241行ainListActivity。您正在打印那裏沒有適當的味精打印時間正在評論該行。如果您分享在該行代碼行,這將有助於我縮小它

+0

Log.d(TAG,contents.get(I)。總結= NULL contents.get(0)。總結:!? 「NULL」); 這也是我在上面粘貼的onPostExecute()方法。你可以從那裏檢查這條線的背景 – user3585510

+0

,因爲它的日誌語句我想你可以避免這種情況。我認爲「contents.get(0).summary」存在問題。最有可能的值是空 – pvn

+0

還有一件事。我從網上獲得的內容是HTML ..現在,當我設置我的文本視圖爲該字符串..它顯示爲包括它的標籤..我怎麼能顯示它爲HTML,沒有標籤 – user3585510

0

看起來這是做什麼...

Log.d(TAG,contents.get(I)。總結!= null?contents.get(0).summary:「NULL」);

確保您的日誌消息不爲空,在這種情況下,content.get(0).summary。

相關問題