android: no class def found error from library pro

2019-02-22 12:52发布

i am getting a noclassdeffound exception, when running my app with the emulator:

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    Intent myIntent = new Intent(ActivityPano.this, ActivityTable.class);
    startActivity(myIntent);
}

the ActivityTable is causing the exception.

it is defined in an android-library project, which i have included in the java build path as well as in the android references dialog. there are no errors in eclipse, but when started in the emulator it crashes.

here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mypackage"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:debuggable="false" android:description="@string/description">
        <activity android:name=".ActivityHPanorama"
                  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="com.mypackage.ActivityTable"></activity>

    </application>


<uses-sdk android:minSdkVersion="3"></uses-sdk>
</manifest> 

this is the error from the logcat:

04-18 11:32:07.767: ERROR/dalvikvm(483): Could not find class com.mypackage.ActivityTable', referenced from method com.mypackage.ActivityHPanorama.onCreate

what makes me a bit suspicious is this line from the console (not the logcat):

[2011-04-18 14:55:59 - panorama] Could not find panorama.apk!

panorama is the name of the library project.

4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-02-22 13:14

The problem is that you haven't defined any intent-filters for your "ActivityTable" as well...

<activity android:name=".ActivityTable" 
                  android:label="ActivityTable">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

This should help..

查看更多
你好瞎i
3楼-- · 2019-02-22 13:17

I think you should use

 Intent myScreen = new Intent();
    myScreen.setClassName(YourCurrentScreen.this,
fullpackagename.yourclassName.class.getName());
    startActivityForResult(myScreen, 0);

This would definitely work

查看更多
冷血范
4楼-- · 2019-02-22 13:19

If you are depenedencies are correct when you are installing the app you should see following in console logs

[2011-04-19 16:41:10 - TicTacToe] Installing TicTacToe.apk...

[2011-04-19 16:41:12 - TicTacToe] Success!

But since you were mentioning that Could not find panorama.apk! I tried replicating such behaviour using tic-tac-toe sameple library..

This is what i did,

Added TicTacToe Library to eclipse, Added TicTacToe app also to eclipse.

Right clicked on Library project, went to android tab and removed the IsLibrary check

Right clicked on Main app project, went to android tab removed dependency

The went to java build path of Main app project and added Library project as required project

Compilation went fine, but when installing the app it is checking for library.apk I am guessing if you are doing anything similar tat might be the issue.

[2011-04-19 16:42:16 - TicTacToe] Installing TicTacToe.apk...

[2011-04-19 16:42:20 - TicTacToe] Success! [2011-04-19 16:42:20 - TicTacToe] Project dependency found, installing: TicTacToeLib

[2011-04-19 16:42:20 - TicTacToeLib] Uploading TicTacToeLib.apk onto device 'SH0A5PL08769' [2011-04-19 16:42:20 - TicTacToeLib] Installing TicTacToeLib.apk... [2011-04-19 16:42:24 - TicTacToeLib] Success!

查看更多
【Aperson】
5楼-- · 2019-02-22 13:26

have you add this class in your Manifest?

<activity android:name="ActivityTable"></activity>

查看更多
登录 后发表回答