0

按照本教程,我在 IntelliJ IDEA 中的 Android 项目中添加了 Maven、ABS 和 AndroidAnnotations。起初,我一直在为DEX/无法访问 android.support.v4.app.FragmentActivity异常而苦苦挣扎,并且似乎使用以下配置对其进行了修复:

应用程序部门

腹肌

现在我得到java.lang.RuntimeException: Unable to start activity错误。

显现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="ru.erarta.erarta"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <application android:label="@string/app_name"
                 android:theme="@style/Theme.Sherlock"
                 android:icon="@drawable/ic_launcher"
                 android:name=".Erarta">
        <activity android:name=".TabsFragmentActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".DayActivity_" />
        <activity android:name=".CalendarActivity"/>
        <activity android:name=".AboutActivity"/>
        <activity android:name=".EventActivity"/>
        <activity android:name=".PermanentExhibitionActivity"/>
        <activity android:name=".MediaActivity"/>
        <activity android:name=".MapActivity"/>
        <activity android:name=".TypesActivity" android:label="Типы событий"/>
        <!-- uses-library android:name="com.google.android.maps" /-->
    </application>
</manifest>

主要活动声明:

public class TabsFragmentActivity extends SherlockFragmentActivity
        implements TabHost.OnTabChangeListener

日志输出:

04-09 16:45:48.614: ERROR/AndroidRuntime(26562): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.erarta.erarta/ru.erarta.erarta.TabsFragmentActivity}: java.lang.ClassCastException: ru.erarta.erarta.CalendarActivity
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1872)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
        at android.app.ActivityThread.access$1500(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:150)
        at android.app.ActivityThread.main(ActivityThread.java:4385)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.ClassCastException: ru.erarta.erarta.CalendarActivity
        at android.support.v4.app.Fragment.instantiate(Fragment.java:384)
        at ru.erarta.erarta.TabsFragmentActivity.onTabChanged(TabsFragmentActivity.java:108)
        at ru.erarta.erarta.TabsFragmentActivity.initialiseTabHost(TabsFragmentActivity.java:73)
        at ru.erarta.erarta.TabsFragmentActivity.onCreate(TabsFragmentActivity.java:51)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
        ... 11 more

我在apktool这里反编译了 APK $ find . | grep support

./smali/android/support
./smali/android/support/v4
./smali/android/support/v4/app
./smali/android/support/v4/app/Watson$OnCreateOptionsMenuListener.smali
./smali/android/support/v4/app/Watson$OnOptionsItemSelectedListener.smali
./smali/android/support/v4/app/Watson$OnPrepareOptionsMenuListener.smali
./smali/android/support/v4/app/Watson.smali
./smali/com/actionbarsherlock/internal/view/View_HasStateListenerSupport.smali

这是 TabsFragmentActivity.java:108 周围的代码:

public void onTabChanged(String tag) {
    TabInfo newTab = this.mapTabInfo.get(tag);
    if (mLastTab != newTab) {
        FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
        if (mLastTab != null) {
            if (mLastTab.fragment != null) {
                ft.detach(mLastTab.fragment);
            }
        }
        if (newTab != null) {
            if (newTab.fragment == null) {
                newTab.fragment = Fragment.instantiate(this,
                        newTab.clss.getName(), newTab.args);
                ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
            } else {
                ft.attach(newTab.fragment);
            }
        }

        mLastTab = newTab;
        ft.commit();
        this.getSupportFragmentManager().executePendingTransactions();
    }
}
4

1 回答 1

0

问题很基本:我试图把FragmentActivity而不是Fragment在标签中。这是ABS组的相关讨论。

于 2013-04-09T16:00:54.453 回答