在logcat中没有线索的NullPointerException

时间:2015-06-13 07:05:32

标签: java android nullpointerexception

我违反了最佳做法,试图解决这个问题,所以从这开始,我意识到这一点,并且我很欣赏任何见解。我做的很简单,依赖于很多Dialog调用。没有什么花哨的,没有调用很多碎片。我的游戏不需要任何权限。

随着背景故事的消失,我得到了这个NPE:

06-13 01:29:03.581  24690-24690/com.myapp.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.myapp.myapp, PID: 24690
    java.lang.NullPointerException
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:309)
            at android.view.View.measure(View.java:17388)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
            at android.view.View.measure(View.java:17388)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
            at android.view.View.measure(View.java:17388)
            at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2217)
            at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1354)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1553)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1238)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6473)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
            at android.view.Choreographer.doCallbacks(Choreographer.java:603)
            at android.view.Choreographer.doFrame(Choreographer.java:573)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)

在我非常平坦的应用程序中,我这样做:

public static MainActivity ACTIVITY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ACTIVITY = this;
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        ACTIVITY.setContentView(R.layout.activity_main);

然后我做了一堆工作正常的东西。问题是,我打电话给一个做战斗事件的班级:

FightEvent thisFight = new FightEvent(this);
    ALLOWSAVE = false;
    thisFight.doFightEvent();

在那堂课中,当战斗开始时,我会这样做:

ACTIVITY.setContentView(R.layout.activity_fight);

当我退出战斗时,我会这样做:

ACTIVITY.setContentView(R.layout.activity_main);

PLOT TWIST:这在旧版本中都可以正常使用。我正在努力使我的游戏100%兼容回到API 8。

在API 8 API 19-22中运行良好,而不是那么多。

帮助?

0 个答案:

没有答案