No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing
No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing instance of type SmsUtils (e.g. x.new A() where x is an instance of SmsUtils).
今天在寫一個短信發(fā)送的工具類時使用到了內(nèi)部類,在實例化內(nèi)部類時遇到此錯誤。
SmsResult result = new SmsResult();
沒有可以訪問SmsUtils類型的封閉實例。必須使用封閉的SmsUtils類型的實例來限定分配(例如,x.new A(),其中x是SmsUtils的一個實例)。
SmsResult?是一個(非靜態(tài)的)內(nèi)部類。?正在從靜態(tài)上下文創(chuàng)建它。您需要提供一個Server實例作為外部實例。但是,幾乎可以肯定我想讓?SmsResult?成為一個靜態(tài)的嵌套類,或者可能是一個外部類。
剛好今天看到一篇文章中提到:?
今天面試我問你static關(guān)鍵字有哪些作用,如果你答出static修飾變量、修飾方法我會認(rèn)為你合格,答出靜態(tài)塊,我會認(rèn)為你不錯,答出靜態(tài)內(nèi)部類我會認(rèn)為你很好,答出靜態(tài)導(dǎo)包我會對你很滿意,因為能看出你非常熱衷研究技術(shù)。
給?SmsResult 類的定義添加 static 關(guān)鍵字就ok了。
總結(jié)
以上是生活随笔為你收集整理的No enclosing instance of type SmsUtils is accessible. Must qualify the allocation with an enclosing的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python基础学习四 函数
- 下一篇: 【289】◀▶ Python I/O