Error generation:
Java code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://blog.csdn.net/zeng622peng/archive/2010/12/25/6097346.aspx# ">
- PrivateContext mcontext;
- @ Override
- Protected VoidOncreate (bundle savedinstancestate) {mcontext = getapplicationcontext ();
- System. Out. println ("mcontext =" + mcontext );
- }
Java code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://blog.csdn.net/zeng622peng/archive/2010/12/25/6097346.aspx# ">
- NewAlertdialog. Builder (mcontext)
- . Seticon (Android. R. drawable. ic_dialog_alert)
- . Settitle ("warnning ")
- . Setmessage (
- "You forget to write the message. Do you want to fill out it ?? ")
- . Setpositivebutton ("yes", positivelistener). setnegativebutton (
- "No", negativelistener). Create (). Show ();
This error is reported in the new alertdialog. builder (mcontext), although the parameter here is alertdialog. builder (context), but we cannot use the context obtained by getapplicationcontext (). Instead, we must use activity, because only one activity can add a form.
Solution: use activity. This (activity is the name of your activity) to fill the parameters in new alertdialog. Builder (context) to create a correct dialog.
Java code {
DP. Sh. toolbar. copytoclipboard (this); Return false;
} "Href =" http://blog.csdn.net/zeng622peng/archive/2010/12/25/6097346.aspx# ">
- NewAlertdialog. Builder (myactivity.This)
- . Seticon (Android. R. drawable. ic_dialog_alert)
- . Settitle ("warnning ")
- . Setmessage (
- "You forget to write the message. Do you want to fill out it ?? ")
- . Setpositivebutton ("yes", positivelistener). setnegativebutton (
- "No", negativelistener). Create (). Show ();
Solve the problem!