Java异常解决:Constructor call must be the first statement in a constructor

当我在这个构造函数中调用其他构造函数时出现了这个错误

	public Busline(int id,String lineNum,String type,String startAndEndTime,
			String company,String startRoute,String endRoute,
			String mark,String other)
	{
               this.id = id;
		this(lineNum,type,startAndEndTime,
				company,startRoute,endRoute,
				mark,other);
	}

原来是构造函数必须放在第一行,这是哪门子规定啊,没办法,改过来吧!

	public Busline(int id,String lineNum,String type,String startAndEndTime,
			String company,String startRoute,String endRoute,
			String mark,String other)
	{
		this(lineNum,type,startAndEndTime,
				company,startRoute,endRoute,
				mark,other);
		this.id = id;
	}

这样就好了,又学习了。

你可能感兴趣的:(JAVA)