A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© @coffee 中级黑马   /  2015-2-4 00:10  /  913 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 @coffee 于 2015-2-5 15:33 编辑

package pack;

import java.lang.reflect.Constructor;


public class ReflectTest {

        /**
         * @param args
         */
        public static void main(String[] args)throws Exception {
                // TODO Auto-generated method stub
                ReflectPoint al = new ReflectPoint(3,5);
               
                Field fieldy = al.getClass().getField("y");

                System.out.println(fieldy.get(al));
        }

}


//被调用函数

public class ReflectPoint {
        
        private int x;
        public int y;
        public ReflectPoint(int x, int y) {
                super();
                this.x = x;
                this.y = y;
        }
}
/*错误提示:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
        Field cannot be resolved to a type

        at pack.ReflectTest.main(ReflectTest.java:41)

*/

3 个回复

倒序浏览
你这代码在同一个JAVA文件里吧= =

点评

最前面两个都有包名,怎么可能是同一个class  发表于 2015-2-4 21:13
回复 使用道具 举报
Imp_x 发表于 2015-2-4 18:47
你这代码在同一个JAVA文件里吧= =

恩!    多谢了 我已经知道错因啦:handshake
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马