2012-11-29 36 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()

相关问题