import java.lang.reflect.*;
class Rect
{ double width,height,area;
public double getArea()
{ area=height*width;
return area;
}
}
public class Example4_35
{ public static void main(String args[])
{ Rect rect=new Rect();
Class cs=rect.getClass();
String className=cs.getName();
Constructor[] con=cs.getDeclaredConstructors();
Field[] field=cs.getDeclareFields();
Method[] method=cs.getDeclareMethods();
System.out.println("类的名字:"+className);
System.out.println("类中有如下的成员变量:");
for( int i=0;i<field.length;i++)
{ System.out.println(field[i].toString());
}
System.out.println("类中有如下的方法:");
for(int i=0;i<method.length;i++)
{ System.out.println(method[i].toString());
}
System.out.println("类中有如下的构造方法:");
for(int i=0;i<con.length;i++)
{ System.out.println(con[i].toString());
}
}
}
和书对照了 没发现自己敲错了 实在找不到哪错了
错误提示
Example4_35.java:15: 找不到符号
符号: 方法 getDeclareFields()
位置: 类 java.lang.Class
Field[] field=cs.getDeclareFields();
^
Example4_35.java:16: 找不到符号
符号: 方法 getDeclareMethods()
位置: 类 java.lang.Class
Method[] method=cs.getDeclareMethods();
^
2 错误E:\j2se\book\4>java Example4_35
Exception in thread "main" java.lang.NoClassDefFoundError: Example4_35
class Rect
{ double width,height,area;
public double getArea()
{ area=height*width;
return area;
}
}
public class Example4_35
{ public static void main(String args[])
{ Rect rect=new Rect();
Class cs=rect.getClass();
String className=cs.getName();
Constructor[] con=cs.getDeclaredConstructors();
Field[] field=cs.getDeclareFields();
Method[] method=cs.getDeclareMethods();
System.out.println("类的名字:"+className);
System.out.println("类中有如下的成员变量:");
for( int i=0;i<field.length;i++)
{ System.out.println(field[i].toString());
}
System.out.println("类中有如下的方法:");
for(int i=0;i<method.length;i++)
{ System.out.println(method[i].toString());
}
System.out.println("类中有如下的构造方法:");
for(int i=0;i<con.length;i++)
{ System.out.println(con[i].toString());
}
}
}
和书对照了 没发现自己敲错了 实在找不到哪错了
错误提示
Example4_35.java:15: 找不到符号
符号: 方法 getDeclareFields()
位置: 类 java.lang.Class
Field[] field=cs.getDeclareFields();
^
Example4_35.java:16: 找不到符号
符号: 方法 getDeclareMethods()
位置: 类 java.lang.Class
Method[] method=cs.getDeclareMethods();
^
2 错误E:\j2se\book\4>java Example4_35
Exception in thread "main" java.lang.NoClassDefFoundError: Example4_35
解决方案 »
- byte[]数组与String转换
- 请问一些类库的jar包是什么啊?
- 能否设置eclipse在不同的workspace下开启或禁用某些插件?
- 寻找rose的视频教程
- 谁有“JAVA无难事(视频教学,12CD-ROM)”的光盘啊?
- 哪位兄弟有Java2 SDK的源代码?
- 在数据库中参数的输入 使用PreparedStatement对象出错
- JB6盘中不含 Borland Enterprise Server AppServer5.0,各位快载一个上去吧!
- 那能下到Jbulider的中文帮助?
- Linux系统中使用RXTX找不到串口
- type mismatch : cannot conver from object to int[]
- 请懂jdbcrowset的朋友指点一二,来者有分
getDeclaredFields(); 漏了个d
Method[] method=cs.getDeclaredMethods();
我刚刚找了好久,发现和了一个dMethod[] method=cs.getDeclareMethods();-->
Method[] method=cs.getDeclaredMethods();Field[] field=cs.getDeclareFields(); --->
Field[] field=cs.getDeclaredFields();
getDeclaredFields();
估计服务器做了缓存,没更新,要么就是.net太破了