简体   繁体   English

找不到类异常Android

[英]Class Not found Exception Android

I am trying to learn android programming and I am creating an app that starts with a splash screen and loads a menu class after that. 我正在尝试学习android编程,并且正在创建一个以启动屏幕开头并在此之后加载菜单类的应用。 the problem is I get this exception 问题是我得到这个异常

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

I understand what the exception states but I do not understand why this is happening. 我了解异常的状态,但不了解为什么会发生这种情况。 In my splash screen class I load the Menu activity like this 在我的启动画面类中,我像这样加载Menu活动

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();

and the menu class is defined in the manifest file like this 并在清单文件中定义菜单类,如下所示

    <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>

When i was loading a main activity with two buttons and a label everything was working ok. 当我通过两个按钮和一个标签加载主要活动时,一切正常。 But when I changed it (inside my splash screen activity) so it would load Menu Activity it keeps giving me this error. 但是,当我更改它时(在我的启动屏幕活动中),这样它将加载菜单活动,但始终会出现此错误。

Thanks in advance 提前致谢

Right click on your project goto properties. 右键单击项目的goto属性。 Java Build Path. Java构建路径。 Choose Order export tab. 选择订单导出标签。 Make sure that Android Private Libraries is selected. 确保已选择“ Android私有库”。 If you have referenced library project. 如果已引用库项目。 do the same for the library project also. 对库项目也要这样做。 Clean and Build. 清洁并建造。

Maybe you should use this: 也许你应该使用这个:

Intent mainApp = new Intent(this,com.em.example1.MENU.class);
startActivity(mainApp);

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();

the stuff f in manifest before what you listed is what? 您列出的清单中清单中的f是什么? What you are looking for is that to seee what the app package name is.. 您在寻找的是看到应用程序包名称是什么。

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. 尝试转到“ Project -> Properties -> Java Build Path -> Order & Export并确保已为您的项目以及您正在使用的所有其他库项目检查了Android私有库。 Clean all projects afterwards and see what happens. 之后清理所有项目 ,看看会发生什么。

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. 事实证明,这个错误太简单了,无法实现……我在Android Manifest中将菜单Menu一词大写,而不仅是动作名称。 Thanks for trying to help me everyone 感谢您尝试帮助我大家

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM