'Not a statement, void type not allowed here error
public static void printTable() {
List<UAccounts> alldata = dataviewing();
for (int i = 0; i < alldata.size(); i++) {
System.out.println( alldata.get(i).getUserID()+"\t"
+ alldata.get(i).getUsername() + "\t" + alldata.get(i).getForename() + "\t")
+ alldata.get(i).getSurname() + "\t" + alldata.get(i).getPassword() + "\t"
+ alldata.get(i).getIsadmin();
};
}
Sorry I'm guessing this is probably an obvious fix but I'm very new to java and cant seem to figure it out. On the line that reads System.out.println( alldata.get(i).getUserID()+"\t" I am receiving a not a statement error as well as void type not allowed here. If anyone could tell me where I'm going wrong and what i would need to change it to to make it work it would be much appreciated.
Solution 1:[1]
In your print statement you have the closing parentheses wrong:
System.out.println( alldata.get(i).getUserID()+"\t"
+ alldata.get(i).getUsername() + "\t" + alldata.get(i).getForename() + "\t") // it is here
+ alldata.get(i).getSurname() + "\t" + alldata.get(i).getPassword() + "\t"
+ alldata.get(i).getIsadmin(); // but should be here
You need to fix it like this
System.out.println( alldata.get(i).getUserID()+"\t"
+ alldata.get(i).getUsername() + "\t" + alldata.get(i).getForename() + "\t"
+ alldata.get(i).getSurname() + "\t" + alldata.get(i).getPassword() + "\t"
+ alldata.get(i).getIsadmin());
Basically what you currently have is
System.out.println("some string") + "some other string";
System.out.println("some string") returns void (nothing) and you cannot append a string to nothing.
Solution 2:[2]
Changed to:
public static void printTable() {
List<UAccounts> alldata = dataviewing();
for (int i = 0; i < alldata.size(); i++) {
System.out.println( alldata.get(i).getUserID()+"\t"
+ alldata.get(i).getUsername() + "\t" + alldata.get(i).getForename() + "\t"
+ alldata.get(i).getSurname() + "\t" + alldata.get(i).getPassword() + "\t"
+ alldata.get(i).getIsadmin());
};
}
Make sure paired chars match each other. You can use a plugin such as Bracket pair colorization to make it easy.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thomas Kläger |
| Solution 2 |
