【问题标题】:Fragment :opening activity from fragment giving ActivityNotFoundException:片段:从给出 ActivityNotFoundException 的片段打开活动:
【发布时间】:2013-04-19 11:59:26
【问题描述】:

我正在尝试从Listfragment 打开一个activity,如下所示

@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        ((MenuActivity)getActivity()).getSlideoutHelper().close();
        Intent myIntent = new Intent(getActivity(), TravellerTimer.class);
        getActivity().startActivity(myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY));

    }

我在清单文件中注册了TimeTraveller 活动,但仍然提供ActivityNotFoundException

以下是我的日志跟踪

04-19 17:14:00.030: E/AndroidRuntime(12188): FATAL EXCEPTION: main
04-19 17:14:00.030: E/AndroidRuntime(12188): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.vpiabstest/com.example.activity.TravellerTimer}; have you declared this activity in your AndroidManifest.xml?
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Activity.startActivityForResult(Activity.java:3446)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Activity.startActivityForResult(Activity.java:3407)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:674)
04-19 17:14:00.030: E/AndroidRuntime(12188):    at android.app.Activity.startActivity(Activity.java:3617)

下面是我的清单文件

< application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <receiver android:name=".service.ActivityService" />
    <receiver
        android:name=".service.StartupService"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

    <activity android:name="SampleActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".MenuActivity"
        android:label="@string/app_name"
        android:theme="@style/MenuTheme" >
    </activity>
    <activity
        android:name=".VpiAbsTestActivity"
        android:theme="@style/Theme.VPI" />
    <activity
        android:name="com.example.activity.CreateTimer"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.EditTimer"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.FakeCall"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.ContactList"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.TravellerTimer"
        android:configChanges="keyboardHidden|orientation|screenSize" />
    <activity
        android:name="com.example.activity.TimerPrefrence"
        android:configChanges="keyboardHidden|orientation|screenSize" />

< /application>

感谢任何帮助。谢谢

【问题讨论】:

  • 请仔细阅读您的 logcat 错误。它说您是否在 AndroidManifest.xml 中声明了此活动?你这样做了吗?
  • have you declared this activity in your AndroidManifest.xml?不用问
  • 是的,我确实在清单中注册了
  • 你写过:“我在清单文件中注册了 TimeTraveller 活动,但仍然给出了 ActivityNotFoundException”。 logcat 说 com.example.activity.TravellerTimer 未找到。检查拼写。
  • @Santhosh 现在它的 gving classcastexception 原因:java.lang.ClassCastException:android.app.Application 无法转换为 com.example.activity.TimerPrefrence 04-19 17:45:20.445:E/ AndroidRuntime(15697): 在 com.example.activity.TravellerTimer.onCreate(TravellerTimer.java:48) 04-19 17:45:20.445: E/AndroidRuntime(15697): 在 android.app.Activity.performCreate(Activity.java :5206) 04-19 17:45:20.445: E/AndroidRuntime(15697): 在

标签: android android-fragments activitynotfoundexception


【解决方案1】:

确保您已在清单中使用完整正确的包名称注册 Activity

【讨论】:

【解决方案2】:

尝试使用 'this' 关键字在意图参数中调用您的活动的当前类对象。

Intent myIntent = new Intent(this.Urcurrentactivity, TravellerTimer.class);      this.Urcurrentactivity.startActivity(myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY));

您的代码也应该可以工作,但只是看到这个引号,我无法确定。

【讨论】:

    【解决方案3】:

    通过在 PasteBin 中查看您的代码:

    ArrayList<ActiveTimer> timerLists = new ArrayList<ActiveTimer>();
    timerLists = ((TimerPrefrence) getApplication()).viewTimer();
    

    您正在尝试将 TimerPrefrence 转换为 ActiveTimer ArrayList。这就是你得到 Class cast 异常的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      相关资源
      最近更新 更多