当前位置: 代码迷 >> Java相关 >> cannot found symbol错误
  详细解决方案

cannot found symbol错误

热度:445   发布时间:2007-01-10 17:23:12.0
cannot found symbol错误

程序如下:
import java.util.*;

class rr
{
LinkedList threadList = new LinkedList();
public int n=0;
public rr(int i,LinkedList thrList)
{
n=i;
threadList=thrList;
if(i!=0)
System.out.println(threadList.getFirst().n);
}

}

public class Fr {
public static void main(String s[]) {

LinkedList threadList=new LinkedList();
for(int i=0;i<2;i++)
{
rr obr=new rr(i,threadList);
threadList.add(obr);
}

}
}

搜索更多相关的解决方案: symbol  cannot  found  LinkedList  public  

----------------解决方案--------------------------------------------------------
以下是引用しΟν∈→魈在2007-1-10 17:23:12的发言:

程序如下:
import java.util.*;

class rr
{
LinkedList threadList = new LinkedList();
public int n=0;
public rr(int i,LinkedList thrList)
{
n=i;
threadList=thrList;
if(i!=0)
System.out.println(threadList.getFirst().n);// 这里的.n是哪里来的,threadList.getFirst()返回的是Object
}

}

public class Fr {
public static void main(String s[]) {

LinkedList threadList=new LinkedList();
for(int i=0;i<2;i++)
{
rr obr=new rr(i,threadList);
threadList.add(obr);
}

}
}


----------------解决方案--------------------------------------------------------

要程序要自己多小心,并且自己学会排除一些简单的错误


----------------解决方案--------------------------------------------------------

  是我发错程序了:下面我做过强制转换了啊,还是错
import java.util.*;

class rr
{
LinkedList threadList = new LinkedList();
public int n=0;
public rr(int i,LinkedList thrList)
{
n=i;
threadList=thrList;
if(i!=0)
System.out.println((rr)threadList.getFirst().n);
}

}

public class Fr {
public static void main(String s[]) {

LinkedList threadList=new LinkedList();
for(int i=0;i<2;i++)
{
rr obr=new rr(i,threadList);
threadList.add(obr);
}

}
}


----------------解决方案--------------------------------------------------------
改成这样System.out.println(((rr)threadList.getFirst()).n);多加一个括号!!
但是我不知道为什么,冰封老大能讲下么?   晕死 搞了半个小时还是这个问题,开始我就是没加括号 所以不知道错在哪?  

----------------解决方案--------------------------------------------------------
这就是括号的作用域问题

因为点"."运算符的优先率是最高的,所以会先取.运算,后括号

所以你要把整个括起来才有用

----------------解决方案--------------------------------------------------------

----------------解决方案--------------------------------------------------------
  相关解决方案