简体   繁体   English

Unity3d Android应用因com.unity3d.player.ga上的NullPointerException崩溃

[英]Unity3d Android app crashes with NullPointerException at com.unity3d.player.g.a

My unity3d android app crashes with with NullPointerException at com.unity3d.player.ga on resuming app from background. 从后台恢复应用程序时,我的unity3d android应用程序在com.unity3d.player.ga上由于NullPointerException而崩溃。 I am new to unity and could not figure out what might be causing this. 我是团结的新手,不知道是什么原因造成的。 I have given the crash log below. 我在下面给出了崩溃日志。

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)

I have given my activity class below 我在下面给了我的活动课

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);
    }
}

The game crashes in line 游戏崩溃了

mUnityPlayer.init(glesMode, trueColor8888); mUnityPlayer.init(glesMode,trueColor8888);

Can anyone help solve this issue. 任何人都可以帮助解决此问题。 Thanks in advance. 提前致谢。

EDIT: My app crashed on myActivity extending UnityPlayerActivity instead of Activity with following crash report 编辑:我的应用程序在myActivity崩溃时扩展了UnityPlayerActivity而不是Activity,并带有以下崩溃报告

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

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

It is problem of your unity version. 这是您的统一版本的问题。 It crashes on unity 4.1. 它在unity 4.1上崩溃。 Try to run it on unity 4.2 or 3.5 and it will run fine. 尝试在unity 4.2或3.5上运行它,它将正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM