我创建了一个类来处理一个简单的消息弹出窗口,这样我就可以在整个应用程序中重用代码。我似乎无法正确理解上下文。这是从各处调用的,通常是从没有直接 UI 的类调用的。请参阅下面的行...
public class msg {
public void msghand(String message, Exception e) {
{
String s;
if (e != null)
{
s= message + "\n" + e.getLocalizedMessage() + " " + e.toString();
}
else
{
s= message ;
}
new AlertDialog.Builder( getApplicationContext () ) <<<< HERE IS THE PROBLEM
.setMessage(s)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create()
.show();
}
}
}