0

你好 Stack Overflow 的好人,我在编写应用程序时遇到了问题,这从我的标题中可以看出。我想做的只是播放一首歌,循环播放,每当触摸屏幕时播放音效。我正在使用 libgdx 库执行此操作,因为我正在尝试学习它以进行更高级的使用。这是代码。

package main;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;

public class AudioExample implements ApplicationListener {
    Music music;
    Sound sound;

    @Override
    public void create() {
        music = Gdx.audio.newMusic(Gdx.files.internal("data/02 - Butterfly.mp3"));
        sound = Gdx.audio.newSound(Gdx.files.internal("data/Collision8-Bit.ogg"));

        music.setLooping(true);
        music.setVolume(0.5f);
        music.play();
    }

    @Override
    public void dispose() {
        music.dispose();
        sound.dispose();
    }

    @Override
    public void pause() {
    }

    @Override
    public void render() {
        if (Gdx.input.justTouched()) 
            sound.play();
    }

    @Override
    public void resize(int arg0, int arg1) {
    }

    @Override
    public void resume() {
    }

}

这是活动。

package com.habel;

import main.AudioExample;

import com.badlogic.gdx.backends.android.AndroidApplication;

import android.os.Bundle;

public class SuperAwesome extends AndroidApplication {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initialize(new AudioExample(), false);
    }
}

该应用程序甚至不会启动。提前谢谢你的帮助。

06-11 22:12:40.700: ERROR/dalvikvm(19767): could not disable core file generation for pid 19767, errno=1
06-11 22:12:40.809: ERROR/AndroidRuntime(19767): FATAL EXCEPTION: main
06-11 22:12:40.809: ERROR/AndroidRuntime(19767): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.habel/com.habel.SuperAweomeActivity}: java.lang.ClassNotFoundException: com.habel.SuperAweomeActivity in loader dalvik.system.PathClassLoader[/data/app/com.habel-2.apk]
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.ActivityThread.access$2500(ActivityThread.java:129)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.os.Looper.loop(Looper.java:143)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.ActivityThread.main(ActivityThread.java:4701)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at java.lang.reflect.Method.invokeNative(Native Method)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at java.lang.reflect.Method.invoke(Method.java:521)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at dalvik.system.NativeStart.main(Native Method)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767): Caused by: java.lang.ClassNotFoundException: com.habel.SuperAweomeActivity in loader dalvik.system.PathClassLoader[/data/app/com.habel-2.apk]
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2651)
06-11 22:12:40.809: ERROR/AndroidRuntime(19767):     ... 11 more
06-11 22:12:40.817: ERROR/ANRInfo(1259): Force Close Dialog not Displayed - showDialog=true mSleeping=true
4

1 回答 1

1

您的日志消息说:

06-11 22:12:40.809: ERROR/AndroidRuntime(19767): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.habel/com.habel.SuperAweomeActivity}: java.lang.ClassNotFoundException: com.habel.SuperAweomeActivity in loader dalvik.system.PathClassLoader[/data/app/com.habel-2.apk]

您将 Awesome 拼写为 Aweome(可能在您的清单中),所以它找不到您的 Activity

(另外,它看起来像是被称为 SuperAwesome 而不是 SuperAwesomeActivity)

于 2011-06-12T02:18:42.453 回答