亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

No enclosing instance of type SignOutDialog is accessible.

標簽:
Android

最近在自定义dialog的时候,在编译写一个例子时。结果编译时出现:

No enclosing instance of type SignOutDialog is accessible. Must qualify the allocation with an enclosing instance of type SignOutDialog (e.g. x.new A() where x is an instance of SignOutDialog).

根据提示,没有可访问的内部类E的实例,必须分配一个合适的内部类E的实例

于是百度谷歌了一下相关资料。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态

方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。

所以在不做其他变动的情况下,最简单的解决办法是将public class改为public static class.

例子:

public static class Builder {//添加static即可!


private Context context;

private String message;

private String title;

private View contentView;

private String positiveButtonText;

private String negativeButtonText;

private DialogInterface.OnClickListener positiveButtonClickListener;

private DialogInterface.OnClickListener negativeButtonClickListener;


public Builder(Context context) {

this.context = context;


}


public Builder setMessage(String message) {//


this.message = message;

return this;

}

public Builder setMessage(int message){

this.message = (String) context.getText(message);

return this;

}


public Builder setTitle(String title) {

this.title = title;

return this;


}

public Builder setTitle(int title){

this.title = (String) context.getText(title);

return this;

}

public Builder setContentView(View v){

this.contentView = v;

return null;

}


public Builder setPositiveButton(String positiveButtonText,OnClickListener onClickListener) {

this.positiveButtonText = positiveButtonText;

this.positiveButtonClickListener = onClickListener;

return this;


}

public Builder setPositiveButton(int positiveButtonText,OnClickListener onClickListener) {

this.positiveButtonText = (String) context.getText(positiveButtonText);

this.positiveButtonClickListener = onClickListener;

return this;

}


public Builder setNegativeButton(String negativeButtonText,OnClickListener onClickListener) {

this.negativeButtonText = negativeButtonText;

this.negativeButtonClickListener = onClickListener;

return this;

}

public Builder setNegativeButton(int negativeButtonText,OnClickListener onClickListener) {

this.negativeButtonText = (String) context.getText(negativeButtonText);

this.negativeButtonClickListener = onClickListener;

return this;

}

原文链接:http://www.apkbus.com/blog-784586-61339.html

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消