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..
}
創建obj的將其設置爲
Button
文本按鈕出這個方法。按鈕=(按鈕)findViewById(R.id.btnChange); –你是什麼意思創建一個對象?那我怎麼能改變按鈕的屬性呢?你能給我一些代碼示例嗎? – Naskov
Button button =(Button)findViewById(R.id.btnChange);在你的活動中去除這個。你可以在上面的方法中使用button.setText()。 –