onActivityResult不能使用R中的资源

时间:2012-11-28 21:53:42

标签: java android android-activity

我有一个调用子Activity的父活动,在onActivityResult()中我尝试setContentView(R.drawable.color_syncing)时得到一个ResourceNotFound异常。我可以 对View的其他操作但不能使用来自R的任何资源。任何想法为什么?

在主要班级..

Intent wifiHelperIntent = new Intent(context,WifiHandlerActivity.class);
startActivityForResult(wifiHelperIntent, WIFI_HANDLER_SUB_ACTIVITY_ID);

在儿童班:

private void doFinish() {
log("Finishing wifi...");
setResult(RESULT_OK);
finish();
}

然后回到主类:onActivityResult:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case WIFI_HANDLER_SUB_ACTIVITY_ID:
            MonollaLog.log("In onActivityResult from WIFI_HANDLER");
            setContentView(R.drawable.color_syncing);
            return;
        default:
            throw new RuntimeException("Unrecognized sub activity request code: "
                    + requestCode);
        }       
}

错误堆栈跟踪:[我在子活动开始之前成功使用了此文件]

11-28 14:56:26.312:E / AndroidRuntime(27346):java.lang.RuntimeException:将结果ResultInfo {who = null,request = 1,result = 1,data = null}传递给activity {com .monolla.mfbcolor / com.monolla.mfbcolor.MainActivity}:android.content.res.Resources $ NotFoundException:来自xml类型布局资源ID的文件res / drawable / color_syncing.jpg#0x7f020003

2 个答案:

答案 0 :(得分:1)

setContentView(int)期望传入布局 ID,您尝试使用颜色。你的意思是传递R.layout.something形式的东西吗?

答案 1 :(得分:1)

setContentView(R.layout.main);,您传递了drawable而不是layout