//第一個文件Paras.java package mypackimport java.io.*;
import java.util.*;
import java.lang.*; public class Paras
 {
   private Object pName;
 
   public void setAbc(String pName) {
   
     this.pName =pName;
  
    }   public void setPName(String pName) {
   
     this.pName =pName;
  
    }   public Object getPName() {
   
      return pName;
  
    } }
//第二個文件test.java
package mypack;
 
import java.io.*;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.*;public class test{
   public static void main(String args[]) throws Exception {
 Paras p1 = new Paras();
  p1.setAbc("tesetestset");
   }}

解决方案 »

  1.   

    我这编译没有错误呀。是不是Paras.java没有编译生成class文件呀我也是初学者
      

  2.   

    首先先謝謝你的回貼.這是我第一次發貼喔,你是第一個回貼喔。呵呵。
    我有看過.到底有沒有生成class。但是有生成的如果把 p1.setAbc("tesetestset");改為
     p1.setPName("tesetestset");就不報錯了。
      

  3.   

    你程序当中有package mypack得包,你编译好的文件是否都放到包当中去了。
      

  4.   


    我是用ant 來編譯的.內容如下:
    <?xml version="1.0"?>
    <project name="Learning Hibernate" default="prepare" basedir=".">  <!-- Set up properties containing important project directories -->
      <property name="source.root" value="src"/>
      <property name="class.root" value="WEB-INF/classes"/>
      <property name="lib.dir" value="WEB-INF/lib"/>  <!-- Set up the class path for compilation and execution -->
      <path id="project.class.path">
          <!-- Include our own classes, of course -->
          <pathelement location="${class.root}" />
          <!-- Include jars in the project library directory -->
          <fileset dir="${lib.dir}">
            <include name="*.jar"/>
          </fileset>
      </path>
     
      <!-- Create our runtime subdirectories and copy resources into them -->
      <target name="prepare" description="Sets up build structures">
        <delete dir="${class.root}"/>
        <mkdir dir="${class.root}"/>    <!-- Copy our property files and O/R mappings for use at runtime -->
        <copy todir="${class.root}" >
          <fileset dir="${source.root}" >
            <include name="**/*.properties"/>
            <include name="**/*.hbm.xml"/>
            <include name="**/*.xml"/>
            <include name="**/*.gif"/>
          </fileset>
        </copy>
      </target>  <!-- Compile the java source of the project -->
      <target name="compile" depends="prepare"
              description="Compiles all Java classes">
        <javac srcdir="${source.root}"
               destdir="${class.root}"
               debug="on"
               optimize="off"
               deprecation="on">
          <classpath refid="project.class.path"/>
        </javac>
      </target>  <target name="run" description="Run a Hibernate sample"
              depends="compile">
        <java classname="mypack.test" fork="true">
          <arg value="NativeTester" />
          <classpath refid="project.class.path"/>
        </java>
      </target></project>但當我運行ant run 編譯及運行時就會有以下錯誤提示》prepare:
       [delete] Deleting directory C:\tomcat\webapps\helloapp\WEB-INF\classes
        [mkdir] Created dir: C:\tomcat\webapps\helloapp\WEB-INF\classes
         [copy] Copying 5 files to C:\tomcat\webapps\helloapp\WEB-INF\classescompile:
        [javac] Compiling 5 source files to C:\tomcat\webapps\helloapp\WEB-INF\classes
        [javac] C:\tomcat\webapps\helloapp\src\mypack\test.java:12: cannot find symbol
        [javac] symbol  : method setAbc(java.lang.String)
        [javac] location: class mypack.Paras
        [javac]   p1.setAbc("tesetestset");
        [javac]     ^
        [javac] 1 errorBUILD FAILED
      

  5.   

    我这里用JBuilder2005编译也是一点问题也没有
      

  6.   

    当然有错了,你的SetAbc()方法,并没有对应的GET方法。怎么会得到值呢。