今天在编译 java 程序时遇到如下问题 :
No se puede acceder a ninguna instancia de adjunta de Type PrintListFromTailTohead. Debe calificar la asignación con una instancia de adjunto
de tipo printListFromTailTohead (egxnew a () donde x es una instancia de printListFromTailTohead).
源代码为 :
public class printListFromTailTohead {public static void main (string [] args) {listNode one = new ListNode (1); listNode two = new ListNode (2); listNode tres = new ListNode (3); One.Next = Two; Two.Next = Three; ArrayList <Deger> Result = Result = printListFromTailTohead (uno); system.out.println ("结果是 :" + resultado);} class ListNode {public int val; public listNode Next; public ListNode () {} public ListNode (int val) {this.val = val;}} public static arrayList <ToNerger> printListFromTailTohead (listNodeNodeDeDEHEAD (listnode) {Stack <Integer> stack = new 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 ());} return ArrayList;}}问题解释 :
代码中 , 我的 ListNode 类是定义在 PrintListFromTailTohead 类中的内部类。listnode 内部类是动态的内部类 , 而我的 Main 方法是 estática 静态的。
就好比静态的方法不能调用动态的方法一样。
有两种解决办法 :
第一种 :
将内部类 ListNode 定义成静态 estático 的类。
第二种 :
将内部类 ListNode 在 PrintListFromTailTohead 类外边定义。
两种解决方法 :
第一种 :
public class printListFromTailTohead {public static void main (string [] args) {listNode one = new ListNode (1); listNode two = new ListNode (2); listNode tres = new ListNode (3); One.Next = Two; Two.Next = Three; ArrayList <Deger> Result = Result = printListFromTailTohead (One); System.out.println ("结果是 :" + resultado);} class static listNode {public int val; public listNode Next; public listNode () {} public listNode (int val) {this.val = val;}}第二种 :
public class printListFromTailTohead {public static void main (string [] args) {listNode one = new ListNode (1); listNode two = new ListNode (2); listNode tres = new ListNode (3); One.Next = Two; Two.Next = tres;} public static arrayList <TinGerger> printListListLodeDeDead (listOndead (listOnEndead (list) {Stack <Integer> stack = new 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 ());} return arrayList;}} class ListNode {public int val; public listNode Next; public listNode () {} public ListNode (int val) {this.val = val;}}}以上所述是小编给大家介绍的 Java 解决 No hay instancia de encerrado de tipo imprime printFromTailTohead es accesible 问题的两种方案 希望对大家有所帮助。 希望对大家有所帮助。 希望对大家有所帮助。 希望对大家有所帮助。 希望对大家有所帮助。