【发布时间】:2015-02-12 02:02:22
【问题描述】:
我在获取带有 id 的 imageview 控件时出错
错误是,
12-13 08:06:56.914: E/AndroidRuntime(1967): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { dat=content://media/external/images/media/26 }} to activity {com.example.hakslogin/com.example.hakslogin.QuestionActivityDynamic}: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.ImageView
获取它的代码是,
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
String imgid=String.valueOf(requestCode);
img = (ImageView) findViewById(requestCode);
img.setImageURI(selectedImageUri);
}
这里我没有提到动态创建imageview的代码,但是我的imageview id是0。
在线出错,
img = (ImageView) findViewById(requestCode);
希望您的建议
【问题讨论】:
-
你调用 startActivityForResult() 方法的地方,也贴出代码。
标签: java android dynamic imageview android-imageview