Libgdx外部存储导致的NullPointerException在Android [英] Libgdx external storage causes NullPointerException on Android
问题描述
我无法访问Android上的外部存储与GDX库。任何帮助将是AP preciated!
I'm having trouble accessing external storage on Android with the Gdx library. Any help would be appreciated!
简体code:
import android.app.Activity;
import android.os.Bundle;
import com.badlogic.gdx.Gdx;
public class Mp3AndFftTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gdx.files.isExternalStorageAvailable();
}
}
这会导致:
ERROR AndroidRuntime FATAL EXCEPTION: main
ERROR AndroidRuntime java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cmbryan.android/com.cmbryan.android.Mp3AndFftTest}: java.lang.NullPointerException
ERROR AndroidRuntime at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
ERROR AndroidRuntime at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
ERROR AndroidRuntime at android.app.ActivityThread.access$1500(ActivityThread.java:117)
ERROR AndroidRuntime at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
ERROR AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR AndroidRuntime at android.os.Looper.loop(Looper.java:123)
ERROR AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:3683)
ERROR AndroidRuntime at java.lang.reflect.Method.invokeNative(Native Method)
ERROR AndroidRuntime at java.lang.reflect.Method.invoke(Method.java:507)
ERROR AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
ERROR AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
ERROR AndroidRuntime at dalvik.system.NativeStart.main(Native Method)
ERROR AndroidRuntime Caused by: java.lang.NullPointerException
ERROR AndroidRuntime at com.cmbryan.android.Mp3AndFftTest.onCreate(Mp3AndFftTest.java:17)
ERROR AndroidRuntime at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
ERROR AndroidRuntime at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
ERROR AndroidRuntime ... 11 more
我在Android清单正确的权限,并在模拟器和实际设备进行测试。我在想什么?难道是因为我使用NetBeans,也许??
I have correct permissions in the Android manifest, and have tested on the emulator and a real device. What am I missing? Is it because I'm using netbeans, maybe??
推荐答案
17号线是:
Gdx.files.isExternalStorageAvailable();
吧? Gdx.files
为空。这是因为你还没有运行GDX初始化code,它树立全局快捷键在 GDX
。您需要创建一个 ApplicationListener
,并把它传递给 AndroidApplication.initialize(..)
。
right? Gdx.files
is null. This is because you haven't run the GDX initialization code that sets up the global shortcuts in Gdx
. You need to create an ApplicationListener
and pass it to AndroidApplication.initialize(..)
.
请按照这里的例子: HTTP://$c$c.google .COM / p / libgdx /维基/ ProjectSetup
libGDX的状态是不明确的,直到你完成了所有预期的初始化。 libGDX不仅仅是一个库更可以消耗件出来,其处理您的应用程序的完整安装和初始化了一个框架。
libGDX's state is ill-defined until you've completed all the expected initialization. libGDX is more than just a library you can consume pieces out of, its a framework that handles the complete setup and initialization of your app.
这篇关于Libgdx外部存储导致的NullPointerException在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!