今天在编译 Java 程序时遇到如下问题 :
Aucune instance entourant de type printlistFromtailtohead n'est accessible. Doit qualifier l'allocation avec une instance d'enclu
de type printlistFromtailtohead (egxnew a () où x est une instance de printlistfromtailtohead).
:
classe publique printlistFromtailtohead {public static void main (String [] args) {listNode one = new ListNode (1); listNode Two = new ListNode (2); listNode Three = new ListNode (3); one.next = Two; Two.next = trois; ArrayList <INTERDN> RESULT = ALLUS Résultat);} classe ListNode {public int Val; public listNode Next; public listNode () {} public listNode (int Val) {this.val = val;}} public static ArrayList <Neger> printlistFromtoTohead (listNode listNode) {stack <infl {stack.push (listNode.val); listNode = listNode.next;} arrayList <Integer> arrayList = new ArrayList <Integer> (); while (! stack.isempty ()) {arrayList.add (stack.pop ());} return arrayList;}}}}}}}}}}}}}}}}}:
代码中 , 我的 ListNode 类是定义在 PrintListFromtailTohead 类中的内部类。ListNode 内部类是动态的内部类 , 而我的 Main 方法是 statique 静态的。
就好比静态的方法不能调用动态的方法一样。
:
:
将内部类 listNode 定义成静态 statique 的类。
:
将内部类 ListNode 在 Printlistfromtailtohead 类外边定义。
:
:
classe publique printlistFromtailtohead {public static void main (String [] args) {listNode one = new ListNode (1); listNode Two = new ListNode (2); listNode Three = new ListNode (3); one.next = Two; Two.next = trois; ArrayList <INTERDN> RESULT = ALLUS résultat);} classe statique listNode {public int Val; public listNode Next; public listNode () {} public listNode (int Val) {this.val = val;}}:
classe publique printlistFromtailtohead {public static void main (String [] args) {listNode one = new ListNode (1); listNode Two = new ListNode (2); listNode Three = new ListNode (3); One.Next = Two; Two.next = Three;} public static ArrayList <inger> PrintListFromtToHoad (ListNode) Stack <Integer> (); while (listNode! = Null) {stack.push (listNode.val); listNode = listNode.next;} ArrayList <Integer> ArrayList = new ArrayList <Integer> (); while (! Stack.isempty ()) {ArrayList.add (stack.pop ());} RETOUR ARRAYLIST int Val; public listNode Next; public listNode () {} public listNode (int val) {this.val = val;}}以上所述是小编给大家介绍的 Java 解决 Aucune instance d'enclusion de type printlistfromtailtohead est accessible 问题的两种方案 , 希望对大家有所帮助。