gpt4 book ai didi

java - 和引擎警报对话框错误

转载 作者:行者123 更新时间:2023-12-01 14:04:05 26 4
gpt4 key购买 nike

error java.lang.RuntimeException: Can't create handler inside 
thread that has not called Looper.prepare() =(

如果我在 GameActivity 中调用 showDialog (id) - 有效但是如果我从另一个类调用 activity.showDialog - 一个错误

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
Log.d("Dialog", "Dialog 1");
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Help");
alert.setMessage("Help");
WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
alert.setView(wv);

AlertDialog ALERT = alert.create();
return ALERT;
default:
return null;
}
}

我想调用任何其他类的对话框

更新:

 new code activiti.runOnUiUpdate()

@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1:
this.runOnUiThread(new Runnable() {
@Override
public void run() {

Log.d("Dialog", "Dialog 1");
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Help");
alert.setMessage("Help");
WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
AlertDialog aALERT = alert.create();

}
});
return ALERT;
default:
return null;
}
}

最佳答案

在更新线程方法中创建对话框,示例

 activity.runOnUiThread(new Runnable(){
@Override
public void run() {
//code for dialog creation goes here
}

});

更新从this到 Activity 上下文activity的所有内部引用您也可以在创建它的最后使用 dialog.show() 并使其在创建后显示。希望我有所帮助。

关于java - 和引擎警报对话框错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19076721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com