android活动中的classnotfoundexception

时间:2012-07-17 18:20:11

标签: android exception

我有2个按钮链接到2个不同的xml文件。一个按钮可以正常工作,但当我点击另一个按钮时,应用程序崩溃,我的logcat向我发送了一堆错误。

这是logcat返回的内容

07-17 18:09:37.067: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-17 18:09:37.077: E/AndroidRuntime(329): FATAL EXCEPTION: main
07-17 18:09:37.077: E/AndroidRuntime(329): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.com.proto1/com``.example.com.proto1.Voiceprompt}: java.lang.ClassNotFoundException: com.example.com.proto1.Voiceprompt in loader dalvik.system.PathClassLoader[/data/app/com.example.com.proto1-2.apk]
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.os.Looper.loop(Looper.java:123)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-17 18:09:37.077: E/AndroidRuntime(329):  at java.lang.reflect.Method.invokeNative(Native Method)
07-17 18:09:37.077: E/AndroidRuntime(329):  at java.lang.reflect.Method.invoke(Method.java:507)
07-17 18:09:37.077: E/AndroidRuntime(329):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-17 18:09:37.077: E/AndroidRuntime(329):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-17 18:09:37.077: E/AndroidRuntime(329):  at dalvik.system.NativeStart.main(Native Method)
07-17 18:09:37.077: E/AndroidRuntime(329): Caused by: java.lang.ClassNotFoundException: com.example.com.proto1.Voiceprompt in loader dalvik.system.PathClassLoader[/data/app/com.example.com.proto1-2.apk]
07-17 18:09:37.077: E/AndroidRuntime(329):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
07-17 18:09:37.077: E/AndroidRuntime(329):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
07-17 18:09:37.077: E/AndroidRuntime(329):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-17 18:09:37.077: E/AndroidRuntime(329):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
07-17 18:09:37.077: E/AndroidRuntime(329):  ... 11 more

我注意到由错误引起的并且认为它是源。

这是我使用它和我的清单的java。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.com.proto1"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".mainj"
            android:label="@string/title_activity_mainj" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MENU" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Infoactive"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.INFOSCREEN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Voiceprompt"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.VOICEPROMPTS" />

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

</manifest>

package com.example.com.proto1;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class menu extends Activity {

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

        // Button Sound
        final MediaPlayer buttonSound = MediaPlayer.create(menu.this,
                R.raw.button_click);

        // Setting up the button references
        Button info = (Button) findViewById(R.id.aboutbutton);
        Button voice = (Button) findViewById(R.id.voicebutton);

        info.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                buttonSound.start();
                startActivity(new Intent("android.intent.action.INFOSCREEN"));

            }
        });

        voice.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                buttonSound.start();
                Intent voiceIntent = new Intent("android.intent.action.VOICEPROMPTS");
                startActivity(voiceIntent);
            }
        });

    }
}

0 个答案:

没有答案