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

时间:2013-07-19 07:41:22

标签: android nullpointerexception unity3d runtimeexception

我的unity3d安卓应用程序在 com.unity3d.player.g.a 上与 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);

任何人都可以帮助解决这个问题。提前谢谢。

编辑:我的应用程序崩溃 myActivity 扩展 UnityPlayerActivity 而不是活动以及以下崩溃报告

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

2 个答案:

答案 0 :(得分:0)

我认为您需要在使用UnityPlayer时从UnityPlayerActivity而不是Activity扩展您的活动。

答案 1 :(得分:0)

这是你的统一版本的问题。它在团结4.1中崩溃。尝试在Unity 4.2或3.5上运行它,它会正常运行。