简体   繁体   中英

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.

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.

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM