2015-08-16 76 views
3

我是初學者。每當我嘗試啓動我的Android應用程序,它顯示一個錯誤unfortunately my app has been stopped。現在讓我具體說明一下,我創建了一個pushbots應用程序來獲取通知,並通過將其轉換爲字符串在textview上顯示它。當通知到達時,它會很好地工作,當我點擊通知時,它會在屏幕上顯示字符串,但不會在啓動它時顯示。我之前問過一個關於這個問題的問題,之前,deadfish說可能會發生這種情況,因爲我的bundle是null,所以我盡我所能地爲顯示字符串的textview提供了一個臨時字符串。但它仍然顯示錯誤。我會在啓動我的應用程序時向您展示logcat。我認爲空包是沒有問題的啓動我的Android應用程序顯示錯誤日誌貓沒有幫助?

08-16 08:58:06.868 13447-13454/com.bluestacks.chartapp I/jdwp﹕ Ignoring second debugger -- accepting and dropping 

公共類MainActivity擴展ActionBarActivity {

public static final String TAG = MainActivity.class.getSimpleName(); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Pushbots.sharedInstance().init(this); 
    Intent intent = getIntent(); 


    //log the message in JSON format 
    Log.i(TAG, "Received message >> " + intent.getExtras().toString()); 
    //Retrieve message and extra 
    String message = intent.getExtras().getString("message"); 
    TextView t1 = (TextView)findViewById(R.id.textView); 
    if(message!=null) { 
     t1.setText(message); 
    } 
    else 
    { 
     t1.setText("null"); 
    } 

    Bundle extras = intent.getExtras(); 
    String bigText = null; 
    TextView t2 = (TextView) findViewById(R.id.textView2); 
    if (extras != null && extras.containsKey("bigText")) { 
     bigText = extras.getString("bigText"); 
     t2.setText(bigText); 
    } 
    else{ 
     t2.setText("null"); 
    } 

} 





@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

}

+0

當應用程序崩潰時,從logcat發佈一個完整的堆棧跟蹤。 – Karakuri

+0

String message = intent.getExtras()。getString(「message」); intent可以爲null請確保在試圖獲得額外的 –

回答

1

bundenull所以你的應用程序將強制關閉在該行:

Log.i(TAG, "Received message >> " + intent.getExtras().toString()); 

試試這個:

String message = null; 

    //log the message in JSON format 
    Log.i(TAG, "Received message >> " + intent.getExtras()); 
    //Retrieve message and extra 
    message = intent.getStringExtra("message"); 
    TextView t1 = (TextView)findViewById(R.id.textView); 
    if(message!=null) { 
     t1.setText(message); 
    } 
    else 
    { 
     t1.setText("null"); 
    } 
+0

之前檢查是否意圖不爲null ...還有一個問題(-.-)/該死的!!!!你們呢?編程神? –

+0

不是,只是像你一樣的人前一段時間:) – Minhtdh

相關問題