java出現“No enclosing instance of type XXX is accessible”
今天有個師妹問了我這個程式碼問題,想起之前也有同學問過我這個問題,覺得這個問題挺常見,所以就想記錄下,以下內容轉自https://cloud.tencent.com/info/800ee9743312952016098d63555cb743.html
報錯如下:
Question:No enclosing instance of type MermoryGroup is accessible. Must qualify the allocation with an enclosing instance of type MermoryGroup (e.g. x.new A() where x is an instance of MermoryGroup).
原因如下:
MermoryGroup為內部類,沒有可訪問的內部類MermoryGroup的例項,必須分配一個合適的內部類MermoryGroup的例項(如x.new A(),x必須是MermoryGroup的例項。)
內部類是動態的,也就是開頭以public class開頭。而主程式是public static class main。在Java中,類中的靜態方法不能直接呼叫動態方法。只有將某個內部類修飾為靜態類,然後才能夠在靜態類中呼叫該類的成員變數與成員方法。所以在不做其他變動的情況下,最簡單的解決辦法是將public class改為public static class.
另一種方法:
相關推薦
java出現“No enclosing instance of type XXX is accessible”
今天有個師妹問了我這個程式碼問題,想起之前也有同學問過我這個問題,覺得這個問題挺常見,所以就想記錄下,以下內容轉自https://cloud.tencent.com/info/800ee9743312952016098d63555cb743.html 報錯如下: Question
No enclosing instance of type XXX is accessible
innert classQuestion:No enclosing instance of type MermoryGroup is accessible. Must qualify the allocation with an enclosing instance of type MermoryGroup
Java 報錯No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
解決方案:在Person內部類前面新增static,將內部類宣告為靜態內部類。 原因如下:在Java中 (1)類的靜態方法不能直接呼叫動態方法。 (2)類的靜態方法不能初始化內部類(包括該類的內部類,和其他檔案中的內部類)。 (3)類的靜態方法可以初始化其他類檔
No enclosing instance of type Face is accessible. Must qualify the allocation with an enclosing inst
剛才在練習內部類的時候遇到了這個報錯: No enclosing instance of type Face is accessible. Must qualify the allocation with an enclosing instance of type Face (e.g. x.ne
No fallback instance of type class found for feign client user-service(轉)
getbean match dynamic fort epo class lis pla sat 1、錯誤日誌 在 feign 開啟熔斷,配置 fallback 類,實現當前接口的實現類時,報錯信息如下: Error starting ApplicationCont
No fallback instance of type class found for feign client user-service(轉)
1、錯誤日誌 在 feign 開啟熔斷,配置 fallback 類,實現當前介面的實現類時,報錯資訊如下: Error starting ApplicationContext. To display the conditions report re-run your application with
No qualifying bean of type [XXX.XXX] found for dependency 解決方法
原始碼: @Service public class UserService implements UserServices{ @Autowired UserMapper userMapper ; public boolean
spring註入時報錯::No qualifying bean of type 'xxx.xxMapper'
and class can 解決 base ica fail pri exception 做一個小項目,因為有 baseService,所以偷懶就沒有寫單獨的每個xxService接口,直接寫的xxServiceImpl,結果在service實現類中註入Mapper的時
[java]No qualifying bean of type 解決方法
1.錯誤原因:註解寫錯 2.原理如下: 現在的spring早就已經擺脫了之前一堆xml配置檔案的情況,都是通過註解配置的方式進行依賴注入了,通常情況下,我們會有一個配置類,然後通過AnnotationConfigApplicationContext進行載入 AnnotationCo
JAVA型別直接輸入超過10位報The literal XXX of type int is out of range 解決辦法
Long.parseLong("XXX")或long number=xxxL java long與int取值範圍的問題 1:long l = 1024*1024*1024*4; //02:int i1 = 1024*1024*1024*4; //03:int i2 = 22000000000
E/CrashReport: java.lang.NoSuchFieldError: No field iv_icon of type I in
集成了一個module後報錯: E/CrashReport: java.lang.NoSuchFieldError: No field iv_icon of type I in class Lcom/example/overlaylib/R$id; or its superclasses (
新下載的工程,啟動tomcat出現識別檔案失敗的現象。No qualifying bean of type 'com.kanq.platform.cert.mapper.CertificateSjdr
首選檢查下資料庫配置: 問題資訊描述如下: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with nam
關於spring boot自動注入出現Consider defining a bean of type 'xxx' in your configuration問題解決方案
轉載自: 搭建完spring boot的demo後自然要實現自動注入來體現spring ioc的便利了,但是我在實施過程中出現了這麼一個問題,見下面,這裡找到解決辦法記錄下來,供遇到同樣的問題的同僚參考 Description: Field hel
Exception in thread "main" java.lang.Error: Unresolved compilation problem: No enclosing instance
Exception in thread "main" java.lang.Error: Unresolved compilation problem: No enclosing instanc
記錄錯誤:No qualifying bean of type [com.xxx.xxxxxxService] found for dependency:expected at least 1 bea
No qualifying bean of type [com.xxx.xxxxxxService] found for dependency: expected at least 1 bean which qualifies as autowire candidate fo
ssm框架整合出現的介面註解“No qualifying bean of type found for dependency”
專案結構:出錯位置:在UserController中,對介面注入失敗package controller; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; imp
關於spring boot應用自動注入出現Consider defining a bean of type 'xxx' in your configuration問題解決方案
在做spring cloud的hystrix的時候,寫了一個controller,注入內部類時發生了一個錯誤:看起來就是找不到這個類,問題是我已經寫了這個類:百度後發現有發生同樣問題的童鞋,原來問題出在application類的註解@SpringBootApplication
SpringBoot- springboot集成Redis出現報錯:No qualifying bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory'
ani 集成 autowired rt.jar evaluate tab using getbean iat Springboot將accessToke寫入Redisk 緩存,springboot集成Redis出現報錯 No qualifying bean of type
No qualifying bean of type報錯問題處理
ted don mon ref scan getbean metadata .get 一個 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of typ
spring異步執行報異常No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available
sun type determine ext tde dap 查找 ann def 最近觀察項目運行日誌的時候突然發現了一個異常, [2018-04-03 10:49:07] 100.0.1.246 http-nio-8080-exec-9 DEBUG org.sprin