在从后台恢复应用程序时,我的 unity3d android 应用程序在com.unity3d.player.ga处因NullPointerException而崩溃。我是统一的新手,无法弄清楚可能导致这种情况的原因。我在下面给出了崩溃日志。
07-19 12:58:10.271: E/AndroidRuntime(2593): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.myapp/com.me.myapp.myActivity}: java.lang.NullPointerException
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.ActivityThread.access$600(ActivityThread.java:126)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1172)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.os.Handler.dispatchMessage(Handler.java:99)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.os.Looper.loop(Looper.java:137)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.ActivityThread.main(ActivityThread.java:4586)
07-19 12:58:10.271: E/AndroidRuntime(2593): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 12:58:10.271: E/AndroidRuntime(2593): at java.lang.reflect.Method.invoke(Method.java:511)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-19 12:58:10.271: E/AndroidRuntime(2593): at dalvik.system.NativeStart.main(Native Method)
07-19 12:58:10.271: E/AndroidRuntime(2593): Caused by: java.lang.NullPointerException
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.unity3d.player.g.a(Unknown Source)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.unity3d.player.g.b(Unknown Source)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.unity3d.player.UnityPlayer.resume(Unknown Source)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.unity3d.player.UnityPlayer.a(Unknown Source)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.unity3d.player.UnityPlayer.init(Unknown Source)
07-19 12:58:10.271: E/AndroidRuntime(2593): at com.me.myapp.myActivity.onCreate(myActivity.java:50)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.Activity.performCreate(Activity.java:4635)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-19 12:58:10.271: E/AndroidRuntime(2593): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)
我在下面给出了我的活动课程
package com.me.myapp;
import com.unity3d.player.*;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class myActivity extends Activity
{
private UnityPlayer mUnityPlayer;
// UnityPlayer.init() should be called before attaching the view to a layout.
// UnityPlayer.quit() should be the last thing called; it will terminate the process and not return.
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mUnityPlayer = new UnityPlayer(this);
if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true))
getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
int glesMode = mUnityPlayer.getSettings().getInt("gles_mode", 1);
boolean trueColor8888 = false;
mUnityPlayer.init(glesMode, trueColor8888);
View playerView = mUnityPlayer.getView();
setContentView(playerView);
playerView.requestFocus();
}
protected void onDestroy ()
{
super.onDestroy();
mUnityPlayer.quit();
}
// onPause()/onResume() must be sent to UnityPlayer to enable pause and resource recreation on resume.
protected void onPause()
{
super.onPause();
mUnityPlayer.pause();
if (isFinishing())
mUnityPlayer.quit();
}
protected void onResume()
{
super.onResume();
mUnityPlayer.resume();
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
mUnityPlayer.configurationChanged(newConfig);
}
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
mUnityPlayer.windowFocusChanged(hasFocus);
}
// Pass any keys not handled by (unfocused) views straight to UnityPlayer
public boolean onKeyMultiple(int keyCode, int count, KeyEvent event)
{
return mUnityPlayer.onKeyMultiple(keyCode, count, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyDown(keyCode, event);
}
public boolean onKeyUp(int keyCode, KeyEvent event)
{
return mUnityPlayer.onKeyUp(keyCode, event);
}
}
游戏在排队时崩溃
mUnityPlayer.init(glesMode, trueColor8888);
任何人都可以帮助解决这个问题。提前致谢。
编辑:我的应用程序在扩展UnityPlayerActivity而不是Activity的myActivity上崩溃,并带有以下崩溃报告
08-06 13:08:33.333: E/AndroidRuntime(29765): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.me.myapp/com.me.myapp.myActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.os.Looper.loop(Looper.java:137)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-06 13:08:33.333: E/AndroidRuntime(29765): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 13:08:33.333: E/AndroidRuntime(29765): at java.lang.reflect.Method.invoke(Method.java:525)
08-06 13:08:33.333: E/AndroidRuntime(29765): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-06 13:08:33.333: E/AndroidRuntime(29765): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-06 13:08:33.333: E/AndroidRuntime(29765): at dalvik.system.NativeStart.main(Native Method)
08-06 13:08:33.333: E/AndroidRuntime(29765): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
08-06 13:08:33.333: E/AndroidRuntime(29765): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:226)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.Activity.requestWindowFeature(Activity.java:3264)
08-06 13:08:33.333: E/AndroidRuntime(29765): at com.me.myapp.myActivity.onCreate(myActivity.java:33)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.Activity.performCreate(Activity.java:5133)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-06 13:08:33.333: E/AndroidRuntime(29765): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-06 13:08:33.333: E/AndroidRuntime(29765): ... 11 more