在android中旋转模拟器后的nullpointerexception

时间:2014-07-25 17:24:58

标签: android nullpointerexception rotation emulation

我在使用图像编辑应用程序时旋转模拟器时出现上述问题。它只是因为nullpointerexception而崩溃。以下是与问题相关的代码部分。

HueseekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            public void onProgressChanged(SeekBar arg0, int progress,
                boolean fromUser) {
            try {
                if (picclass.hasBitmap()) {
                    float hue = (float) (progress - 256);
                    float setHue = (float) hue * 360 / 256;
                    picclass.setHue(setHue);

                    if (!noUpdate) {
                        picclass.ApplyFilter();
                        Img.setImageBitmap(picclass.getDisplayedBitmap());
                        mUndoRedo.SetStateForUndoRedo();
                    }
                }
            } catch (OutOfMemoryError ome) {
                AlertDialog ad = adb.create();
                ad.setMessage("Leider reicht der Speicherplatz nicht aus!");
                ad.show();

            }
        }

根据logcat,问题是mUndoRedo.SetStateForUndoRedo();。代码编译好吧。我不明白这个异常是如何在这里触发的。有什么想法吗?

编辑:LOGCAT

07-25 18:26:07.328: D/dalvikvm(5989): GC_CONCURRENT freed 159K, 3% free 9134K/9351K, paused 4ms+3ms
07-25 18:26:07.348: D/TextLayoutCache(5989): Using debug level: 0 - Debug Enabled: 0
07-25 18:26:07.428: D/libEGL(5989): loaded /system/lib/egl/libGLES_android.so
07-25 18:26:07.428: D/libEGL(5989): loaded /system/lib/egl/libEGL_adreno200.so
07-25 18:26:07.438: D/libEGL(5989): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
07-25 18:26:07.438: D/libEGL(5989): loaded /system/lib/egl/libGLESv2_adreno200.so
07-25 18:26:07.478: D/OpenGLRenderer(5989): Enabling debug mode 0
07-25 18:26:10.668: D/OpenGLRenderer(5989): Flushing caches (mode 0)
07-25 18:26:10.688: D/OpenGLRenderer(5989): Flushing caches (mode 0)
07-25 18:26:12.128: D/OpenGLRenderer(5989): Flushing caches (mode 1)
07-25 18:26:15.518: I/System.out(5989): Image Path : /mnt/sdcard/tiny_sd/rocknest_858x188.jpg
07-25 18:26:15.548: D/dalvikvm(5989): GC_FOR_ALLOC freed 102K, 2% free 9314K/9479K, paused 23ms
07-25 18:26:15.548: I/dalvikvm-heap(5989): Grow heap (frag case) to 9.747MB for 645232-byte allocation
07-25 18:26:15.598: D/dalvikvm(5989): GC_CONCURRENT freed 103K, 3% free 9841K/10119K, paused 5ms+2ms
07-25 18:26:15.598: W/CursorWrapperInner(5989): Cursor finalized without prior close()
07-25 18:26:17.538: D/OpenGLRenderer(5989): Flushing caches (mode 0)
07-25 18:26:17.808: D/dalvikvm(5989): GC_FOR_ALLOC freed 86K, 3% free 9902K/10119K, paused 37ms
07-25 18:26:17.808: I/dalvikvm-heap(5989): Grow heap (frag case) to 10.321MB for 645232-byte allocation
07-25 18:26:17.878: D/dalvikvm(5989): GC_CONCURRENT freed 4K, 3% free 10528K/10759K, paused 2ms+2ms
07-25 18:26:17.908: D/dalvikvm(5989): GC_FOR_ALLOC freed <1K, 3% free 10528K/10759K, paused 32ms
07-25 18:26:17.908: I/dalvikvm-heap(5989): Grow heap (frag case) to 10.931MB for 645232-byte allocation
07-25 18:26:17.978: D/dalvikvm(5989): GC_CONCURRENT freed 0K, 3% free 11158K/11399K, paused 5ms+2ms
07-25 18:26:20.098: D/AndroidRuntime(5989): Shutting down VM
07-25 18:26:20.098: W/dalvikvm(5989): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
07-25 18:26:20.108: E/AndroidRuntime(5989): FATAL EXCEPTION: main
07-25 18:26:20.108: E/AndroidRuntime(5989): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.propra_fotoapp/com.example.propra_fotoapp.MainActivity}: java.lang.NullPointerException
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3371)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread.access$700(ActivityThread.java:127)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1162)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.os.Looper.loop(Looper.java:137)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread.main(ActivityThread.java:4441)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at java.lang.reflect.Method.invokeNative(Native Method)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at java.lang.reflect.Method.invoke(Method.java:511)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at dalvik.system.NativeStart.main(Native Method)
07-25 18:26:20.108: E/AndroidRuntime(5989): Caused by: java.lang.NullPointerException
07-25 18:26:20.108: E/AndroidRuntime(5989):     at com.example.propra_fotoapp.MainActivity$13.onProgressChanged(MainActivity.java:269)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.widget.SeekBar.onProgressRefresh(SeekBar.java:89)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:609)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.widget.ProgressBar.refreshProgress(ProgressBar.java:621)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.widget.ProgressBar.setProgress(ProgressBar.java:670)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.widget.ProgressBar.setProgress(ProgressBar.java:651)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.widget.ProgressBar.onRestoreInstanceState(ProgressBar.java:1096)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.view.View.dispatchRestoreInstanceState(View.java:10043)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2425)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2425)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.view.View.restoreHierarchyState(View.java:10021)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1619)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.Activity.onRestoreInstanceState(Activity.java:906)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.Activity.performRestoreInstanceState(Activity.java:878)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1100)
07-25 18:26:20.108: E/AndroidRuntime(5989):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1945)
07-25 18:26:20.108: E/AndroidRuntime(5989):     ... 12 more
07-25 18:26:20.158: D/dalvikvm(5989): GC_CONCURRENT freed 1333K, 13% free 10551K/12039K, paused 2ms+2ms
07-25 18:31:20.198: I/Process(5989): Sending signal. PID: 5989 SIG: 9

2 个答案:

答案 0 :(得分:1)

您需要在销毁活动之前保存捆绑包,然后在重新创建活动时设置捆绑包的值

答案 1 :(得分:-1)

Android操作系统是独一无二的。当您旋转屏幕时,您将自动创建一个新活动,这就是您获得空引用的原因。我的建议是将你的屏幕设置为potrait或landscape。