-1
我得到錯誤,而越來越imageview的控制它的ID動態創建的ImageView無法通過id獲取Android?
誤差,
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()方法,也發佈代碼。 – 2014-12-13 13:32:02