作者:金爽20111018 | 来源:互联网 | 2023-09-02 00:09
EAndroidRuntime:FATALEXCEPTION:mainProcess:websters.smartindiaserviceapp,PID:3320java.lang
E/AndroidRuntime: FATAL EXCEPTION: main
Process: websters.smartindiaserviceapp, PID: 3320
java.lang.RuntimeException: Unable to start activity ComponentInfo{websters.smartindiaserviceapp/websters.smartindiaserviceapp.Activities.WelcomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentTransaction android.support.v4.app.FragmentManager.beginTransaction()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentTransaction android.support.v4.app.FragmentManager.beginTransaction()' on a null object reference
at android.support.v4.app.DialogFragment.dismissInternal(DialogFragment.java:200)
at android.support.v4.app.DialogFragment.dismiss(DialogFragment.java:171)
at websters.smartindiaserviceapp.Activities.WelcomeActivity.onCreate(WelcomeActivity.java:51)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
当我尝试在actvtiy中解除自定义对话框时,我得到这个例外
public class CustomDialog extends DialogFragment {
public static CustomDialog newInstance() {
return new CustomDialog();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dialog, container, false);
Glide.with(this).load(R.drawable.loader).placeholder(R.drawable.loader)
//.dontAnimate()
.into((ImageView) v.findViewById(R.id.progress));
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
if (getDialog() == null)
super.setShowsDialog (false);
return v;
}
}
这是我的自定义对话框类.
我正在使用此代码显示对话框:
.CustomDialog.newInstance()表演(getSupportFragmentManager(), “对话”);工作正常显示对话框
并尝试解雇
使用CustomDialog.newInstance().dismiss();这个代码,但在这里我得到例外请告诉我在哪里做错了如何解雇给对话框.
解决方法:
newInstance每次都会给你一个新的参考
初始化对话框就像
CustomDialog customDialog = CustomDialog.newInstance();
customDialog.show(getSupportFragmentManager(),"Dialog");
解雇使用
customDialog.dismiss();