显示ProgressDialog时崩溃的应用程序。我正在使用滑出式键盘在手机上进行测试。当显示对话框时,我滑动键盘,应用崩溃。
public static class ProgressDialogFragment extends DialogFragment
{
public ProgressDialogFragment()
{
super();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
final ProgressDialog dialog = new ProgressDialog(getActivity());
dialog.setMessage(getString(R.string.dlg_progress_title));
dialog.setIndeterminate(true);
dialog.setCancelable(false);
return dialog;
}
@Override
public void show(FragmentManager manager, String tag)
{
try
{
super.show(manager, tag);
}
catch (IllegalStateException e)
{
Log.d(TAG, e.getMessage());
}
}
}
崩溃日志:
> 04-25 20:49:46.999: E/AndroidRuntime(7904): FATAL EXCEPTION: main
04-25 20:49:46.999: E/AndroidRuntime(7904): java.lang.NullPointerException
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.support.v4.app.DialogFragment.dismissInternal(DialogFragment.java:184)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.support.v4.app.DialogFragment.dismissAllowingStateLoss(DialogFragment.java:165)
04-25 20:49:46.999: E/AndroidRuntime(7904): at com.fisherman.activity.HomeActivity$2.onPostExecute(HomeActivity.java:268)
04-25 20:49:46.999: E/AndroidRuntime(7904): at com.fisherman.activity.HomeActivity$2.onPostExecute(HomeActivity.java:1)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.os.AsyncTask.finish(AsyncTask.java:417)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.os.AsyncTask.access$300(AsyncTask.java:127)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.os.Looper.loop(Looper.java:130)
04-25 20:49:46.999: E/AndroidRuntime(7904): at android.app.ActivityThread.main(ActivityThread.java:3835)
04-25 20:49:46.999: E/AndroidRuntime(7904): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 20:49:46.999: E/AndroidRuntime(7904): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 20:49:46.999: E/AndroidRuntime(7904): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-25 20:49:46.999: E/AndroidRuntime(7904): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-25 20:49:46.999: E/AndroidRuntime(7904): at dalvik.system.NativeStart.main(Native Method)
我做的课是静态的,因为应用程序崩溃:
> 04-25 20:48:50.757: E/AndroidRuntime(7863): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.fisherman.activity.HomeActivity$ProgressDialogFragment: make sure class name exists, is public, and has an empty constructor that is public
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.support.v4.app.Fragment.instantiate(Fragment.java:405)
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1767)
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:208)
04-25 20:48:50.757: E/AndroidRuntime(7863): at com.fisherman.activity.HomeActivity.onCreate(HomeActivity.java:50)
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
04-25 20:48:50.757: E/AndroidRuntime(7863): ... 12 more
04-25 20:48:50.757: E/AndroidRuntime(7863): Caused by: java.lang.InstantiationException: com.fisherman.activity.HomeActivity$ProgressDialogFragment
04-25 20:48:50.757: E/AndroidRuntime(7863): at java.lang.Class.newInstanceImpl(Native Method)
04-25 20:48:50.757: E/AndroidRuntime(7863): at java.lang.Class.newInstance(Class.java:1409)
04-25 20:48:50.757: E/AndroidRuntime(7863): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
最佳答案
您是否关闭了有关执行后的对话框?它可能会创建崩溃的应用
因此,如果您忘记关闭对话框,请在执行后将其关闭。
关于Android:位于DialogFragment.dismiss的NullPointerException处于DialogFragment.dismissAllow的内部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16222698/