3

I'm trying to build a abstract classes in one project as a template and to implement them in another. However when trying to run an Activity that implements the template Activity, the NoClassDefFoundError pops up. I've added the template project to the Java Build Path of the other one, checked it in "Order and Export", cleaned the project, but nothing helps. I also tried to compile the project with the 1.6 compiler. All resulted with the same error. When trying to add the template project as a JAR Eclipse says there's a duplicate of Manifest files and won't allow it.

Does anyone has any idea what else I can do to fix this problem?

Here's the error log I receive:

04-05 00:29:09.941: E/AndroidRuntime(1348): FATAL EXCEPTION: main
04-05 00:29:09.941: E/AndroidRuntime(1348): java.lang.IllegalStateException: Could not execute method of the activity
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.view.View$1.onClick(View.java:2144)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.view.View.performClick(View.java:2485)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.view.View$PerformClick.run(View.java:9080)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.os.Handler.handleCallback(Handler.java:587)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.os.Looper.loop(Looper.java:123)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invokeNative(Native Method)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invoke(Method.java:507)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at dalvik.system.NativeStart.main(Native Method)
04-05 00:29:09.941: E/AndroidRuntime(1348): Caused by: java.lang.reflect.InvocationTargetException
04-05 00:29:09.941: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invokeNative(Native Method)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invoke(Method.java:507)
04-05 00:29:09.941: E/AndroidRuntime(1348):     at android.view.View$1.onClick(View.java:2139)
04-05 00:29:09.941: E/AndroidRuntime(1348):     ... 11 more
04-05 00:29:09.941: E/AndroidRuntime(1348): Caused by: java.lang.NoClassDefFoundError:  scf1984.games.testQuest.TestQuestActivity
04-05 00:29:09.941: E/AndroidRuntime(1348):     at scf1984.games.testQuest.TestMainActivity.startTestQuest(TestMainActivity.java:18)
04-05 00:29:09.941: E/AndroidRuntime(1348):     ... 14 more

And the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="scf1984.games.testQuest"
android:versionCode="1"
android:versionName="1.0" >

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="scf1984.games.testQuest.TestMainActivity"
        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="scf1984.games.testQuest.TestQuestActivity"
        android:label="@string/app_name" >

    </activity>
</application>

</manifest>

The invoking method:

    public void startTestQuest(View v) {
    Intent i = new Intent(this,
            scf1984.games.testQuest.TestQuestActivity.class);
    startActivity(i);
}
scf
  • 396
  • 2
  • 19
  • The error occurs on line 18 of TestMainActivity.java. Please show this line of code as well as some of the surrounding code for context. For example, if this line is in a short method, post the entire method. – Code-Apprentice Apr 05 '13 at 00:46
  • I've added the requested method. – scf Apr 05 '13 at 00:50
  • Is your "template project" an Android library project? If not, mark it as such. (I don't use Eclipse much, so I don't know the exact steps to do this.) – Code-Apprentice Apr 05 '13 at 00:53
  • 1
    That did the trick. I just went to Project->Properties->Android and checked the "is library". I also had to go to the same window for the implementing project and add the template project to the list of used libraries, regardless of the build path. Thanks! – scf Apr 05 '13 at 01:08
  • Added as an answer. Feel free to edit with the exact steps. A green check mark and an upvote would be appreciated, too ;-) – Code-Apprentice Apr 05 '13 at 01:25

3 Answers3

2

You need to mark your "template project" as an Android library project. Go to Project->Properties->Android and checked the "is library".

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • That did the trick. I just went to Project->Properties->Android and checked the "is library". I also had to go to the same window for the implementing project and add the template project to the list of used libraries, regardless of the build path. Thanks! – scf Apr 05 '13 at 01:40
0

Most likely you're missing the activity declaration in the Android manifest. You should pastebin the full error and your AndroidManifest.xml

f2prateek
  • 2,034
  • 2
  • 20
  • 26
  • Sorry, premature Enter. I edited my original post. I'm not sure what part of the code to show - the error originates from a scf1984.games.testQuest.TestQuestActivity.class call when setting up an Intent. – scf Apr 05 '13 at 00:33
0

Intent intent = (Intent)new Intent();

intent.setClassName(package name, package name + class);

startActivity(intent);

try this

이수홍
  • 43
  • 1
  • 5