标题:程序运行错误是什么原因???
取消只看楼主
yhmwajxx
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2021-10-22
结帖率:100%
 问题点数:0 回复次数:1 
程序运行错误是什么原因???
以下这段代码在运行时提示出错是什么原因?请高手指点.谢谢!
=========================================================================================
JavaProcedure.java:3: 无法从静态上下文中引用非静态 变量 this
                Husband h=new Husband("11111","张三","1999-10-11",null);
                          ^
JavaProcedure.java:4: 无法从静态上下文中引用非静态 变量 this
                Wife w = new Wife("222222","李四","1998-11-12",null);
                         ^
JavaProcedure.java:25: 找不到符号
符号: 变量 Wife
位置: 类 JavaProcedure.Husband
                        Wife=w;
                        ^
3 错误


=========================================================================================
public class JavaProcedure{
    public static void main(String[] args) {
        Husband h=new Husband("11111","张三","1999-10-11",null);
        Wife w = new Wife("222222","李四","1998-11-12",null);
        h.wife=w;
        w.husband=h;
        System.out.println(h.name+"的妻子的名字叫"+h.wife.name);
        System.out.println(w.name+"丈夫的名字叫"+w.husband.name);

        }
        
class Husband{
    String idcard;
    String name;
    String birth;
    Wife wife;
   
    public Husband(){

    }
    public Husband(String s1,String s2,String s3,Wife w){
            idcard = s1;
            name =s2;
            birth =s3;
 k

}
}
class Wife{
    String idcard;
    String name;
    String birth;
    Husband husband;

    public  Wife(){
    }
    public  Wife(String s1,String s2,String s3,Husband h){
            idcard = s1;
            name =s2;
            birth =s3;
            husband =h;
    }
}


}
   
搜索更多相关主题的帖子: name null public new String 
2022-10-27 21:11
yhmwajxx
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2021-10-22
得分:0 
找到原因了,最后一行的}放错位置了。谢谢大家。
2022-10-28 08:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510464-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.103606 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved