Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
子类中的警报对话框在Android中不起作用_Android_Android Alertdialog_Builder - Fatal编程技术网

子类中的警报对话框在Android中不起作用

子类中的警报对话框在Android中不起作用,android,android-alertdialog,builder,Android,Android Alertdialog,Builder,AlertDialog.Builder builder1=新建AlertDialog.BuildergetBaseContext 或 AlertDialog.builder1=新建AlertDialog.Buildercontext 或 AlertDialog AlertDialog=新建AlertDialog.Builderthis.create 如果我在主活动类的任何子类中编写此代码,则上述任何代码都不起作用,应用程序将崩溃 如果我在onCreate方法下编写此代码,那么它可以正常工作。给出

AlertDialog.Builder builder1=新建AlertDialog.BuildergetBaseContext

AlertDialog.builder1=新建AlertDialog.Buildercontext

AlertDialog AlertDialog=新建AlertDialog.Builderthis.create

如果我在主活动类的任何子类中编写此代码,则上述任何代码都不起作用,应用程序将崩溃


如果我在onCreate方法下编写此代码,那么它可以正常工作。

给出一个活动应该可以:

new AlertDialog.Builder(YourActivity.this).create();
请尝试以下代码:

Activity.runOnUiThread(new Runnable() {
                            public void run() {
                                    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
                            }
                        });

显示您的代码和logcat。如果出现崩溃,至少要努力发布logcat。它在哪个类/函数中被调用?@Piyush:我使用的类返回产品列表……….class LoadAllProducts Extendes AsyncTask{}Guyz。。。我的问题与下面链接中提到的问题非常相似:@RajeshJaiswal那么在你的问题中定义更好不起作用