2012-11-29 37 views
0

我想在使用相機拍照後更改Button屬性。java.lang.RuntimeException:將結果傳遞給活動失敗{}:java.lang.NullPointerException

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode != RESULT_OK) return; 

     Bitmap bitmap = utilities.decodeFile(path, 300); 
     imgPicHolder.setImageBitmap(bitmap); 
     //The pic is changing on the previous Activity, this works fine 



     Button button = (Button)findViewById(R.id.btnChange); 
     button.setText("NewText"); 
     //Here is the problem, when trying to change the button property from the previous  activity before taking the picture.. 



} 
+1

創建obj的將其設置爲Button文本按鈕出這個方法。按鈕=(按鈕)findViewById(R.id.btnChange); –

+0

你是什麼意思創建一個對象?那我怎麼能改變按鈕的屬性呢?你能給我一些代碼示例嗎? – Naskov

+0

Button button =(Button)findViewById(R.id.btnChange);在你的活動中去除這個。你可以在上面的方法中使用button.setText()。 –

回答

1

我會做的是通過Intent.putExtra()Activity1Activity2Activity1通過這個String,使用getIntent().getStringExtra()以檢索該string然後在Activity1onResume()

相關問題