问题描述
我使用this解决方案,试图使用“ AlterDialog”显示一个加载框。
public void setProgressDialogRelayResponse() {
int llPadding = 30;
LinearLayout ll = new LinearLayout(mContext);
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setPadding(llPadding,llPadding,llPadding);
ll.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams llParam = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
llParam.gravity = Gravity.CENTER;
ll.setLayoutParams(llParam);
ProgressBar progressBar = new ProgressBar(mContext);
progressBar.setIndeterminate(true);
progressBar.setPadding(0,0);
progressBar.setLayoutParams(llParam);
llParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
llParam.gravity = Gravity.CENTER;
TextView tvText = new TextView(mContext);
tvText.setText("Status Verification.....");
tvText.setTextColor(Color.RED);
tvText.setTextSize(20);
tvText.setLayoutParams(llParam);
ll.addView(progressBar);
ll.addView(tvText);
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setCancelable(true);
builder.setView(ll);
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
Window window = dialog.getWindow();
if (window != null) {
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(dialog.getWindow().getAttributes());
layoutParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(layoutParams);
}
}
它正在显示,但一直在显示。我想在执行某种方法时将其关闭。为此,我要全局设置AlteDialog
。我尝试了以下
public class NewFormFragment extends Fragment {
public AlertDialog dialog = new AlertDialog(); }
它给了我
error: no suitable constructor found for AlertDialog(no arguments)
然后我尝试了以下
public AlertDialog dialog = new AlertDialog(getActivity());
哪个给我下面的错误
错误:找不到适用于AlertDialog(Activity)的合适的构造函数
然后我执行以下操作
error: no suitable constructor found for AlertDialog(Context)
提供:Context mContext;
它也给我同样的错误
错误:找不到适用于AlertDialog(Context)的合适构造函数
最后我尝试了以下
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
public AlertDialog dialog = builder.create();
但是这一次,我的app
在login screen
之后崩溃,并出现以下错误。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thumbsol.accuratemobileassetsmanagament/com.thumbsol.accuratemobileassetsmanagament.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference
at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:224)
at android.app.AlertDialog$Builder.<init>(AlertDialog.java:465)
at com.thumbsol.accuratemobileassetsmanagament.fragment.NewFormFragment.<init>(NewFormFragment.java:339)
at com.thumbsol.accuratemobileassetsmanagament.MainActivity.onCreate(MainActivity.java:76)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
(NewFormFragment.java:339) is hitting at `AlertDialog.Builder builder = new AlertDialog.Builder(mContext);`
任何帮助将不胜感激
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)