LogCat中的Android错误

时间:2014-01-06 17:11:21

标签: java android eclipse logcat android-logcat

首先,我道歉,但我是Android开发和论坛的初学者。 当我在我的模拟器上运行应用程序时,我得到错误; “应用程序(应用程序名称)意外停止。请再试一次。”我正在努力解释我的日志猫。我也尝试在清单和src文件中调整'MAIN'和'MENU'名称以匹配,但知道结果,除非我遗漏了一些东西。 这是我的logcat:

01-06 16:50:32.273: D/dalvikvm(490): GC_EXTERNAL_ALLOC freed 652 objects / 51480 bytes in 92ms
01-06 16:50:37.813: D/AndroidRuntime(490): Shutting down VM
01-06 16:50:37.813: W/dalvikvm(490): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-06 16:50:37.863: E/AndroidRuntime(490): FATAL EXCEPTION: main
01-06 16:50:37.863: E/AndroidRuntime(490): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.knight.baseproject/com.knight.baseproject.com.knight.baseproject.MENU}: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.os.Looper.loop(Looper.java:123)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.reflect.Method.invokeNative(Native Method)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.reflect.Method.invoke(Method.java:521)
01-06 16:50:37.863: E/AndroidRuntime(490):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-06 16:50:37.863: E/AndroidRuntime(490):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-06 16:50:37.863: E/AndroidRuntime(490):  at dalvik.system.NativeStart.main(Native Method)
01-06 16:50:37.863: E/AndroidRuntime(490): Caused by: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]
01-06 16:50:37.863: E/AndroidRuntime(490):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
01-06 16:50:37.863: E/AndroidRuntime(490):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-06 16:50:37.863: E/AndroidRuntime(490):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-06 16:50:37.863: E/AndroidRuntime(490):  ... 11 more

这是清单:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.knight.baseproject.MAIN"
            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.knight.baseproject.MENU"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.knight.baseproject.MENU" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是'MAIN'java脚本:

package com.knight.baseproject;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

public class MAIN extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread logoTimer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                    Intent menuIntent = new Intent("com.knight.baseproject.MENU");
                    startActivity(menuIntent);

                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                finally{
                    finish();
                }
            }
        };
        logoTimer.start();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

'MENU'java(我相信没有影响):

package com.knight.baseproject;

import android.app.Activity;
import android.os.Bundle;

public class MENU extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }



}

5 个答案:

答案 0 :(得分:1)

更改

android:name=".com.knight.baseproject.MENU"

android:name="com.knight.baseproject.MENU"
在你的清单中

答案 1 :(得分:1)

<activity
        android:name=".com.knight.baseproject.MENU"

此名称以.开头,因此它被解释为相对于包名com.knight.baseproject,在异常堆栈跟踪中显示com.knight.baseproject.com.knight.baseproject.MENU

java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]

删除最初的.或将名称更改为.MENU

答案 2 :(得分:0)

您需要在AndroidManifest.xml文件中添加活动。

答案 3 :(得分:0)

尝试以下选项。

选项1

  1. 右键单击您的项目
  2. 点击Android工具
  3. 单击“修复项目属性”
  4. 选项2

    点击项目 - &gt;属性 - &gt; Java构建路径 - &gt;订单和导出,您应该勾选您使用的条目。

    选项3

    删除除Android.x.x以外的所有库,然后按项目清除项目 - &gt;清理然后添加您的库(不要忘记检查顺序和导出)。

    还需要检查的另一个地方是属性 - &gt; Java编译器 - &gt; JDK合规性。

答案 4 :(得分:0)

尝试学习如何调试错误,您可以读取堆栈跟踪并通过调试器运行应用程序。从上到下阅读,你会发现实际发生的事情。

01-06 16:50:37.863: E/AndroidRuntime(490): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.knight.baseproject/com.knight.baseproject.com.knight.baseproject.MENU}: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]

01-06 16:50:37.863: E/AndroidRuntime(490): Caused by: java.lang.ClassNotFoundException: com.knight.baseproject.com.knight.baseproject.MENU in loader dalvik.system.PathClassLoader[/data/app/com.knight.baseproject-2.apk]

如果你正确阅读它,你会发现发生异常&#34; ClassNotFoundException&#34;因为它无法找到班级。

我认为这是因为你没有在你的AndroidManifest.xml中添加你的Activity,你应该在清单文件中定义你在应用程序中使用的任何活动。

如果您可以发布您的代码和放大器,那就太好了。清单。