1

我正在尝试学习 android 编程,我正在创建一个应用程序,该应用程序以启动画面开始,然后加载一个菜单类。问题是我得到了这个异常

06-04 10:59:37.166: E/AndroidRuntime(926): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.em.example1.MENU" on path: /data/app/com.em.example1-1.apk

我了解异常状态,但我不明白为什么会发生这种情况。在我的启动屏幕类中,我像这样加载菜单活动

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                Intent mainApp = new Intent("com.em.example1.MENU");
                startActivity(mainApp);

            }
        }
    };
    timer.start();

并且菜单类在清单文件中定义如下

    <activity
        android:name="com.em.example1.MENU"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.em.example1.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

当我使用两个按钮和一个标签加载主要活动时,一切正常。但是当我改变它(在我的启动屏幕活动中)所以它会加载菜单活动它一直给我这个错误。

提前致谢

4

6 回答 6

3

Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.

于 2013-06-04T11:11:47.013 回答
2

Maybe you should use this:

Intent mainApp = new Intent(this,com.em.example1.MENU.class);
startActivity(mainApp);
于 2013-06-04T11:14:43.123 回答
2

You may use this code, i have made some changes. it may be help u..

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                MENU.this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Intent mainApp = new Intent(MENU.this,com.em.example1.MENU.class);
                        MENU.this.startActivity(mainApp);
                    }
                });


            }
        }
    };
timer.start();
于 2013-06-04T11:22:04.890 回答
1

the stuff f in manifest before what you listed is what? What you are looking for is that to seee what the app package name is..

于 2013-06-04T11:15:27.657 回答
1

Try changing this line in your manifest file.

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

And also try this thing

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. Clean all projects afterwards and see what happens.

于 2013-06-04T11:18:16.920 回答
0

As it turns out I the error was too simple to realize...... I had the word Menu capitalized in Android Manifest in the name and not only in action name. Thanks for trying to help me everyone

于 2013-06-04T20:21:37.190 回答