0
我想在我的應用程序中打開警告對話框的URL的onclick但它開始activity.please的送禮者錯誤告訴我的解決方案警告對話框的onclick應用程序崩潰
public void AlertUpgrade(Activity activity)
{
Log.e("AlertUpgrade", "Communicator.");
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setMessage(" Click OK to Upgrade Now ? ")
.setPositiveButton("OK" +
"", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
Log.e("onClick", "AlertUpgrade");
Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(" "));
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET|Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
startActivity(marketIntent);
}
}
).setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP)
{
return false;
}
return true;
}
});
builder.create().show();
}
錯誤:
04-04 15:40:10.549: E/AndroidRuntime(5142): FATAL EXCEPTION: main
04-04 15:40:10.549: E/AndroidRuntime(5142): java.lang.NullPointerException
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.app.Activity.startActivityForResult(Activity.java:3464)
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.app.Activity.startActivityForResult(Activity.java:3425)
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.app.Activity.startActivity(Activity.java:3661)
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.app.Activity.startActivity(Activity.java:3629)
04-04 15:40:10.549: E/AndroidRuntime(5142): at gsip.webgalaxy.ui.Communicator$2.onClick(Communicator.java:146)
04-04 15:40:10.549: E/AndroidRuntime(5142): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:185)
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.os.Looper.loop(Looper.java:176)
04-04 15:40:10.549: E/AndroidRuntime(5142): at android.app.ActivityThread.main(ActivityThread.java:5419)
04-04 15:40:10.549: E/AndroidRuntime(5142): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 15:40:10.549: E/AndroidRuntime(5142): at java.lang.reflect.Method.invoke(Method.java:525)
04-04 15:40:10.549: E/AndroidRuntime(5142): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
04-04 15:40:10.549: E/AndroidRuntime(5142): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
04-04 15:40:10.549: E/AndroidRuntime(5142): at dalvik.system.NativeStart.main(Native Method)
後Communicator.java在列146 – Blackbelt
使用右鍵在方法 – Saqib
的說法,而活動是你的問題解決了嗎? –