1

我正在尝试将 AndroidAnnotations 添加到我的 maven/idea 项目中。这是我现在拥有的:

显现

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="ua.avtopoisk"
      android:versionCode="1" android:versionName="0.5">

<uses-sdk android:minSdkVersion="1"
          android:targetSdkVersion="8"/>


<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application android:name=".AvtopoiskApplication" android:icon="@drawable/icon"      android:label="@string/app_name">
    <activity android:name=".activites.SearchActivity_"
              android:screenOrientation="portrait"
              android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".activites.SearchResultActivity"
              android:screenOrientation="portrait"
              android:configChanges="keyboardHidden|orientation"
              android:label="@string/app_name"/>
</application>

maven依赖

<dependency>
            <groupId>com.googlecode.androidannotations</groupId>
            <artifactId>androidannotations</artifactId>
            <version>2.6</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.googlecode.androidannotations</groupId>
            <artifactId>androidannotations</artifactId>
            <classifier>api</classifier>
            <version>2.6</version>
        </dependency>

开始活动

@EActivity(R.layout.search)
    public class SearchActivity extends Activity {
    }

我还编辑了我的项目设置,如下所示https://github.com/ealden/android-annotations-idea-test/blob/master/project-settings-guide.png

它编译得很好,但是当我尝试运行这个应用程序时,我收到了这个:

10-16 16:39:49.789: ERROR/AndroidRuntime(15972): FATAL EXCEPTION: main
            java.lang.RuntimeException: Unable to instantiate activity    ComponentInfo{ua.avtopoisk/ua.avtopoisk.activites.SearchActivity_}:   java.lang.ClassNotFoundException: ua.avtopoisk.activites.SearchActivity_ in loader   dalvik.system.PathClassLoader[/data/app/ua.avtopoisk-2.apk]
            at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
            at    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            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:867)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
            at dalvik.system.NativeStart.main(Native Method)
            Caused by: java.lang.ClassNotFoundException:   ua.avtopoisk.activites.SearchActivity_ in loader   dalvik.system.PathClassLoader[/data/app/ua.avtopoisk-2.apk]
            at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
            at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
            at   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
            ... 11 more

如果您能给我任何提示,我将不胜感激。

更新

我发现当我通过 maven 构建我的应用程序时,一切都很好,但是当我通过 IDEA 构建它时,我仍然有 ClassNotFoundException。我仍然不知道出了什么问题

更新 2

我尝试使用 eclipse 构建我的项目,但我遇到了同样的错误。我也尝试构建android注释示例项目(HelloWorldEclipse),我也有同样的错误

4

1 回答 1

0

我发现问题了!带有生成源的文件夹 gen 被 IDEA 排除(设置->编译器->排除)。现在工作正常,但我仍然很感兴趣,这是真的吗。

于 2012-10-17T14:16:00.327 回答