這是我使用沒有可以訪問ContactsXmpp類型的封閉實例嗎?
public class ContactsXmpp extends SherlockFragmentActivity {
private static Context ctx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_xmpp_sip);
ctx = this;
}
我得到錯誤,當我從這個方法調用的AsyncTask類。這是錯誤 No enclosing instance of type ContactsXmpp is accessible. Must qualify the allocation with an enclosing instance of type ContactsXmpp (e.g. x.new A() where x is an instance of ContactsXmpp).
private static void alert(String str, final String name) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx);
alertDialogBuilder.setMessage(str + ": " + name);
alertDialogBuilder.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
Subscription(name);
new ColorsXMPP_AfterLogin().execute(); ///** error getting here..
}
});
alertDialogBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
unSubscribe(name);
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
的AsyncTask這裏
public class ColorsXMPP_AfterLogin extends AsyncTask<AfterLogging, Void, Void> {
private ProgressDialog _dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.e(TAG, " GmailXMPP_AfterLogin onPreExecute");
}
@Override
protected void onPostExecute(Void feed) {
//ProgressBar_hide();
_dialog.dismiss();
Log.e(TAG, " GmailXMPP_AfterLogin onPostExecute");
}
@Override
protected Void doInBackground(AfterLogging... arg0) {
Log.e(TAG, " GmailXMPP_AfterLogin doInBackground");
return null;
}
}
確保您的Assign活動上下文''中的ContactsXmpp''onCreate'方法ctx'調用alert'方法之前 –
是的,我做了正確的,我只分配在onCreate()方法。更新我的代碼看看。 –
new ColorsXMPP_AfterLogin()。execute(ContactsXmpp.this);試試這個我認爲幫助這個.. – QuokMoon