【问题标题】:java.lang.RuntimeException: Failure delivering result to activity {}: java.lang.NullPointerExceptionjava.lang.RuntimeException:将结果传递给活动{}失败:java.lang.NullPointerException
【发布时间】:2012-11-29 10:08:39
【问题描述】:

我正在尝试在使用相机拍照后更改 Button 属性。

@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 button = (Button)findViewById(R.id.btnChange);
  • 创建对象是什么意思?之后我将如何更改按钮的属性?你能给我一些代码示例吗?
  • 按钮按钮 = (Button)findViewById(R.id.btnChange);在你的活动中定义这个。您可以在上述方法中使用 button.setText()。
  • findViewById 将在当前活动中查找视图,如果 Button 在以前的子活动中(现在已死),它显然不起作用。

标签: android android-intent camera


【解决方案1】:

我要做的是将这个StringActivity2传递给Activity1,通过Intent.putExtra()Activity1,使用getIntent().getStringExtra()检索这个string,然后将它设置为ButtonActivity1onResume() 中发短信

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    相关资源
    最近更新 更多