Unity3d的Android应用程序崩溃与NullPointerException异常在com.unity3d.player.g.a

问题描述:

我unity3d的Android应用程序崩溃与从背景恢复应用NullPointerException异常com.unity3d.player.g.a。我对团结并不陌生,无法弄清楚可能是什么原因造成的。下面给出了崩溃日志。Unity3d的Android应用程序崩溃与NullPointerException异常在com.unity3d.player.g.a

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,而不是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 
+0

我们在'at com。*。**。***。onCreate(***。java:50)'? –

+0

我只是想修改我的活动和包名称。它是** com.company.myapp.MainActivity ** – glo

+0

我的意思是'MainActivity.java'上第50行的代码是什么? –

这是你的统一版本的问题。它在统一4.1上崩溃。尝试运行它在统一4.2或3.5,它会运行良好。

我认为你需要从UnityPlayerActivity而不是活动拓展业务,为您使用UnityPlayer。

+0

。它导致我的应用程序崩溃 – glo

+0

我认为你不需要调用'requestWindowFeature(Window.FEATURE_NO_TITLE);'因为它已经从UnityPlayerActivity调用'super.onCreate()' – Hadriel

+0

谢谢你试图提供帮助。这不是一个解决方案。没有冒犯,但你甚至尝试过你正在谈论的东西。 – glo