I'm following a guide on how to create a working interface in Java and I've done the code according to the guide yet I get an error saying Constructor call must be the first statement in a constructor
, even though it is the first statement. I tried multiple solutions so I'm quite lost as none of them worked.
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class test extends JFrame {
private JLabel item1;
private void test () {
super ("Title 1"); //error happens here
}
}
You didn't create a constructor - constructors don't have return type of void. It should be
private test (){
super ("Title 1");
}
but you actually should stick to Java naming conventions and rename your class to Test
.
The constructor should not have a return value
private test () {
super(); // This should do
}
You need to remove the void
from your test
function.
Your code must be like:
public test (){
super ("Frame Title");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.