Hello 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
答案 0 :(得分: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]
你拼写为Aweome的Awesome(可能在你的清单中),因此无法找到你的活动
(另外,它看起来像是SuperAwesome而不是SuperAwesomeActivity)