Java 報錯No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
解決方案:在Person內部類前面新增static,將內部類宣告為靜態內部類。
原因如下:在Java中 (1)類的靜態方法不能直接呼叫動態方法。 (2)類的靜態方法不能初始化內部類(包括該類的內部類,和其他檔案中的內部類)。 (3)類的靜態方法可以初始化其他類檔案中的類。 (4)類的靜態方法可以初始化靜態類(包括靜態內部類)。 真正的原因是:物件的生命週期。 (1)靜態變數和靜態方法的生命週期 靜態變數和靜態方法,在程序建立的時候就被建立了,而不是在物件建立的時候才被建立,並且其生命週期同該程序的生命週期一樣長,其佔用的系統資源是初始化程序申請資源的一部分。 (2)內部類的生命週期 如果是非靜態的內部類,必須由一個已建立的例項去建立一個對應的內部類例項,才能開始其生命週期,但如果是靜態的內部類,則可以直接建立。因為所有的靜態物件,都線上程建立的時候就一起被建立了。
瞭解了這些以後,上面的問題自然就可以解釋的通了。 (1)靜態方法線上程初始化的時候就被建立了,而這時候普通類都還沒來的及初始化,因此不能呼叫它的內部類。 (2)而如果是靜態類,記住一個原則——變數優先於方法被建立。因此靜態方法自然就可以呼叫靜態物件了。 (3)之所以可以在靜態方法中呼叫普通類是因為我們可以手動初始化該普通類。
相關推薦
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
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
spring 報錯 No qualifying bean of type
報錯如下 --------------------------------------------- 嚴重: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error cr
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
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 (
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
mysql報錯:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
detail mode sql_mode reat 配置文件 ESS ssi select color 原因: https://blog.csdn.net/fansili/article/details/78664267 解決辦法: 1:查看mysql配置文件
springMvc中介面返回結果轉換報錯:No converter found for return value of type: class java.util.ArrayList
1.在spring web服務中介面返回結果報錯問題 org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of typ
No qualifying bean of type報錯問題處理
ted don mon ref scan getbean metadata .get 一個 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of typ
配置ssm專案報錯:No qualifying bean of type ... found for dependency ...expected at least 1 bean which
配置ssm專案時,提示提示在service層注入出錯,出錯資訊如下:大致的錯誤資訊為: cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException:
idea新增maven依賴失敗案例之:tomcat啟動總是報錯:No qualifying bean of type 'org.codehaus.jackson.map.ObjectMapper'
=====tomcat啟動總是報錯:No qualifying bean of type 'org.codehaus.jackson.map.ObjectMapper'【原因:maven依賴失敗,沒加版本號】====值得 記錄原因:jd的SDK和這些Jackson相關jar包
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
JUnit的報錯“No tests found with test runner JUnit4”和“The input type of the launch configuration does not exist”
【前言】不爽!!! Eclipse總是報錯: No tests found with test runner JUnit4 首先如下幾點 1 你有沒有匯入Junit包(eclipse中就自帶了)如果用到了spring的測試類有沒匯入 spring-test包 2 你的包版本
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
apt-get update 報錯 W: Unknown Multi-Arch type 'no' for package 'compiz-core'
源 #deb包 deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security