无法解析符号'activityInfo'

时间:2014-10-24 21:46:40

标签: java android android-intent

" r.activityInfo"返回"错误:找不到符号变量activityInfo"在编译

公共类MainActivity扩展了ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d("LP1", "Created");
    super.onCreate(savedInstanceState);

    final Intent mainIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse("http://abc"));
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    final List<ResolveInfo> browsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
    Iterator itr = browsList.iterator();
    while(itr.hasNext()) {
        Object r = itr.next();
        ActivityInfo s = r.activityInfo;
    }

... }

2 个答案:

答案 0 :(得分:2)

您声明Object r,但Object类没有名为activityInfo的成员。

要解决此问题,请使用增强的for循环:

for (ResolveInfo r : browsList) {
    ActivityInfo s = r.activityInfo;
}

答案 1 :(得分:0)

您可以为每个周期添加演员表或使用。

while(itr.hasNext()) {
        ResolveInfo r = (ResolveInfo)itr.next();
        ActivityInfo s = r.activityInfo;
    }