在ProgressDialog期间旋转屏幕时出错

时间:2014-04-02 09:15:54

标签: android

我启动线程。与他一起ProgressDialog。一切正常,但如果运行时ProgressDialog,旋转屏幕应用程序会出错。以及如何制作ProgressDialog而在完成加载之前什么都不能按下?

public static void openImage(final Context context, String link)
    {
        final ProgressDialog prog1 = new ProgressDialog(context);
        NewThread t = new NewThread();
        t.setOnParseResult(new IOnParseResult() {
            @Override
            public void onDone(ArrayList<Map<String, Object>> data, String linknew) {}

            @Override
            public void onImageLinkGet(Bitmap str, String url) {
                b = str;

                context.startActivity(new Intent(context, Photo.class));
                prog1.dismiss();
            }
        });
        prog1.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        prog1.setMessage("Идет загрузка");
        prog1.setIndeterminate(true);
        prog1.setCancelable(true);
        prog1.show();
        t.execute(link,"video");

    }


04-02 16:07:38.928: ERROR/AndroidRuntime(29411): FATAL EXCEPTION: main
        java.lang.NullPointerException
        at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
        at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
        at com.example.GoogleMemu.MyAdapter.<init>(MyAdapter.java:26)
        at com.example.GoogleMemu.MyActivity$PlanetFragment.addData(MyActivity.java:226)
        at com.example.GoogleMemu.MyActivity$2.onDone(MyActivity.java:123)
        at com.example.GoogleMemu.NewThread.onPostExecute(NewThread.java:101)
        at com.example.GoogleMemu.NewThread.onPostExecute(NewThread.java:22)
        at android.os.AsyncTask.finish(AsyncTask.java:602)
        at android.os.AsyncTask.access$600(AsyncTask.java:156)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4464)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:589)
        at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:0)

这种情况正在发生,因为当您旋转设备时,OnCreate()会因为方向发生变化而被调用,您应该保存活动以防止出错。

答案 1 :(得分:0)

在您的活动中覆盖onConfigurationChanged()