Ask coding questions

← Back to all posts
oi its broken
DanielBrammer33 (0)

cheers fix it please cos im trash coder need help 5$ paypal to whoever helps cheers x x x x x x x x x x x x

Answered by mwilki7 (278) [earned 5 cycles]
View Answer
mwilki7 (278)

I could be wrong, it's been a while since I've programmed in Java but:
The thingy that runs your code is looking for a class called "Main"
Try renaming:

class projectpractice


class Main
mwilki7 (278)

I have added 2 new lines to your code here:

Your logic was correct, the only thing you tripped on was Java syntax. (which can be annoying sometimes)

First one is:

    File file = new File("Users.txt");
    Scanner inputfile = new Scanner(file);

It looks like your program is reading from an existing file, instead of a new one, so I used the File class to open it, and scanner reads from it.

The second change:

for(int index = 0; index <= 6 && inputfile.hasNext(); index ++ )

I added a condition: index < 6 && inputfile.hasNext();
makes sure you don't read too much (past the end of the file).

To help you catch errors better I changed the second catch statement

    catch (Exeption ex)
            System.out.println("Something else has gone wrong.");

since it's hard to tell which error was caught if the error code reports the same thing.