我用的是netbeans ide 4.1,我按照官方教程编程序,有两个项目,一个用来定义一个类LibClass,类中有一个函数public static String acrostic(String[] args),还有一个主项目,里面是主类,可是我在主类里引用LibClass类时出了问题,
    public static void main(String[] args) {
        String result=LibClass.acrostic(args);
        System.out.println("Result+"+result);
    }
其中第二句String result=LibClass.acrostic(args);报错,错误是:
cannot find symbol,
symbol:variable LibClass
location:class org.me.myapp.AcrosticExample
其中AcrosticExample是我改了名的主类。
请问这是为什么?怎么解决?谢谢!

解决方案 »

  1.   

    改了名的主类?
    ----------------
    如果java文件有public类,则文件名必须与该类名一直,不能随便改名
    不知道楼主具体是什么情况
      

  2.   

    这个是一个主类:
    package org.me.myapp;
    /*
     * AcrosticExample.java
     *
     * Created on 2005年12月13日, 下午7:49
     *
     * To change this template, choose Tools | Options and locate the template under
     * the Source Creation and Management node. Right-click the template and choose
     * Open. You can then make changes to the template in the Source Editor.
     *//**
     *
     * @author Administrator
     */
    public class AcrosticExample {
        
        /**
         * Creates a new instance of AcrosticExample 
         */
        public AcrosticExample() {
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            String result=LibClass.acrostic(args);
            System.out.println("Result+"+result);
        }
        
    }
    这个是另一个类:
    package org.me.mylib;/**
     *
     * @author Administrator
     */
    public class LibClass {
        
        /** Creates a new instance of LibClass */
        public static String acrostic(String[] args) {
            StringBuffer b = new StringBuffer();
            for (int i = 0; i < args.length; i++) {
                if (args[i].length() > i) {
                    b.append(args[i].charAt(i));
                } else {
                    b.append('?');
                }
            }
            return b.toString();
        }
        public LibClass() {
        }
        
    }
    这都是网上教程中的程序。
      

  3.   

    两个类都在不同的包下,你又没import,显然主类看不到你的LibClass的