java 中出現No enclosing instance of type Test is accessible

看教程,編寫例子時,爲了偷懶方便,在下面直接添加了一個類。由於沒注意}的問題,寫的是內部類。

結果創建後發生:No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).編譯錯誤。

所以解決辦法。

1. 添加static 從內部類變成靜態內部類

2.在創建之時以外部類().new 內部類()

雖然是自己疏忽,但是還是算踩坑了吧,記錄一下~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章