用JAVA与VRML做毕设,找了段程序运行下
编译出错cannot resolve symbol,哪位高手帮忙看下,谢谢!环境变量设置
CLASSPATH.;c:\jdk1.3.1_20\lib;c:\jdk1.3.1_20\lib\tools.jar;c:\jdk1.3.1_20\lib\vrml97.jar;c:\jdk1.3.1_20\jre\lib\rt.jar;c:\jdk1.3.1_20\lib;c:\jdk1.3.1_20\lib\htmlcoverter.jar
PATH  c:\jdk1.3.1_20\bin;c:\jdk1.3.1_20\jre\bin ;C:\Program 报错
F:\javalesson>javac changecolor.java
changecolor.java:31: incompatible types
found   : java.awt.Scrollbar
required: java.awt.Scrollbar[]
                        scrBar=new Scrollbar(Scrollbar.VERTICAL);
                               ^
changecolor.java:32: cannot resolve symbol
symbol  : method add  (java.awt.Scrollbar[])
location: class changecolor
                        add(scrBar);
                        ^
changecolor.java:33: cannot resolve symbol
symbol  : method reshape  (int,int,int,int)
location: class java.awt.Scrollbar[]
                        scrBar.reshape(100+80*i,5,20,160);
                              ^
changecolor.java:34: cannot resolve symbol
symbol  : method setValues  (int,int,int,int)
location: class java.awt.Scrollbar[]
                        scrBar.setValues(50,0,0,10);
                              ^
changecolor.java:35: cannot resolve symbol
symbol  : method getValue  ()
location: class java.awt.Scrollbar[]
                        labelColor=new Label(Text+scrBar.getValue(),Label.LEFT);                                                        ^
changecolor.java:35: incompatible types
found   : java.awt.Label
required: java.awt.Label[]
                        labelColor=new Label(Text+scrBar.getValue(),Label.LEFT);                                   ^
changecolor.java:36: cannot resolve symbol
symbol  : method add  (java.awt.Label[])
location: class changecolor
                        add(labelColor);
                        ^
changecolor.java:37: cannot resolve symbol
symbol  : method setBackground  (java.awt.Color)
location: class java.awt.Label[]
                        labelColor.setBackground(Color.green);
                                  ^
changecolor.java:38: cannot resolve symbol
symbol  : method reshape  (int,int,int,int)
location: class java.awt.Label[]
                        labelColor.reshape(100+80*i,165,40,20);
                                  ^
changecolor.java:64: cannot resolve symbol
symbol  : method getValue  ()
location: class java.awt.Scrollbar[]
                labelColor.setText(Text+scrBar.getValue());
                                              ^
changecolor.java:64: cannot resolve symbol
symbol  : method setText  (java.lang.String)
location: class java.awt.Label[]
                labelColor.setText(Text+scrBar.getValue());
                          ^
changecolor.java:73: cannot resolve symbol
symbol  : method getValue  ()
location: class java.awt.Scrollbar[]
                        value=(float)(scrBar.getValue()/100f);
                                            ^
changecolor.java:73: incompatible types
found   : float
required: float[]
                        value=(float)(scrBar.getValue()/100f);
                              ^
Note: changecolor.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
13 errors
源码
import java.awt.*; 
import java.applet.*; 
import vrml.external.Browser; 
import vrml.external.Node; 
import vrml.external.field.EventInSFColor; 
public class changecolor extends Applet{ 
        Scrollbar scrBar[]=new Scrollbar[3]; 
        Label labelColor[]=new Label[3]; 
        Label labelDemo; 
        Browser browser; 
        Node myMaterial; 
        String Text[]={"R=","G=","B="}; 
        boolean isScenceLoading=true; 
        public void start(){ 
                while (isScenceLoading){ 
                        try{ 
                                browser=Browser.getBrowser(this); 
                                myMaterial=(Node)(browser.getNode("ConeColor")); 
                                isScenceLoading=false; 
                                labelDemo.setText("TestColor"); 
                        } 
                        catch(Exception e){labelDemo.setText("VRML Loading");} 
                } 
        } 
        public void init(){ 
                super.init(); 
                setLayout(null); 
                resize(240,240); 
                setBackground(Color.orange); 
                for(int i=0;i<3;i++){ 
                        scrBar=new Scrollbar(Scrollbar.VERTICAL); 
                        add(scrBar); 
                        scrBar.reshape(100+80*i,5,20,160); 
                        scrBar.setValues(50,0,0,10); 
                        labelColor=new Label(Text+scrBar.getValue(),Label.LEFT); 
                        add(labelColor); 
                        labelColor.setBackground(Color.green); 
                        labelColor.reshape(100+80*i,165,40,20); 
                } 
                labelDemo=new Label("TestColor",Label.CENTER); 
                add(labelDemo); 
                labelDemo.reshape(320,70,80,80); 
                labelDemo.setBackground(new Color(122,122,122)); 
        } 
        public boolean handleEvent(Event event){ 
                for(int i=0;i<3;i++){ 
                        if (event.id==Event.SCROLL_LINE_UP&&event.target==scrBar){ 
                                setColorLabel(event,i); 
                                return true; 
                        } 
                        else if(event.id==Event.SCROLL_LINE_DOWN&&event.target==scrBar){ 
                                setColorLabel(event,i); 
                                return true; 
                        } 
                        else if(event.id==Event.SCROLL_ABSOLUTE&&event.target==scrBar){ 
                                setColorLabel(event,i); 
                            return true; 
                        } 
                } 
                return super.handleEvent(event); 
        } 
        public void setColorLabel(Event ev,int i){ 
                Color demoColor; 
                labelColor.setText(Text+scrBar.getValue()); 
                demoColor=new Color((int)(2.55*scrBar[0].getValue()), 
                        (int)(2.55*scrBar[1].getValue()), 
                        (int)(2.55*scrBar[2].getValue()) 
                        ); 
                labelDemo.setBackground(demoColor); 
                float value[]=new float[3]; 
                EventInSFColor newColor=(EventInSFColor)myMaterial.getEventIn("set_diffuseColor"); 
                for(i=0;i<3;i++) 
                        value=(float)(scrBar.getValue()/100f); 
                newColor.setValue(value); 
        } 

解决方案 »

  1.   

    init方法里 
    scrBar = new Scrollbar(Scrollbar.VERTICAL); 
    属性scrBar是一个数组啊,估计是写掉了scrBar[i],细节咩细节~~``
      

  2.   

    说得好!scrBar 改为scrBar[i],这里要循环!
      

  3.   

    看错误信息慢慢找,得有耐心.
    比如:
    changecolor.java:31: incompatible types 
    found   : java.awt.Scrollbar 
    required: java.awt.Scrollbar[] 
                            scrBar=new Scrollbar(Scrollbar.VERTICAL); 
    这段错误信息,写的很明显了
    changecolor.java的第31行:不相容的类型.
    发现:java.awt.Scrollbar
    需要:java.awt.Scrollbar[] 需要的是数组,你给的并非数组.慢慢找吧.
      

  4.   

    谢谢各位的耐心指正
    cannot resolve symbol 是怎么回事