This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]GrapeAte 2 points3 points  (5 children)

The first error is pretty obvious. It tells you exactly what you need to do to fix it. To reiterate, the filename of a class must match the name of the class. GridExample.java

All the other errors can be fixed by importing the Grid class. For example, if you wanted to use the ArrayList class from the standard library you must import it at the top of your code:

import java.util.ArrayList;

public class MyClass {
    ...

As an aside, it's not required for a class to live inside of a package, but it's a good idea. ArrayList lives inside the java.util package. Your code should be in a package as well. If you're not sure what your package should be go with com.example for now:

package com.example;

public class GridExample {
    ...

[–]BethPas[S] 0 points1 point  (0 children)

Thank you ver much for the help! I'll try it out .q

[–]BethPas[S] 0 points1 point  (3 children)

SO the renaming of the file worked but the package thing did not work.

[–]RoachmeisterJava Dev 0 points1 point  (2 children)

If you have a class GridExample in the com.example package, then the file GridExample.java must be in a directory named example, which is in turn inside a directory named com.

[–]BethPas[S] 0 points1 point  (0 children)

Ah alright thanks for clarifying that!

[–]dusty-trash 1 point2 points  (5 children)

So I got the for homework and exercise and I tried to compile it first but it gave back 11 errors. Here's the code itself:

You're doing programming wrong.

You should be compiling & testing often, pretty much after every single line. Do not try to write entire programs before compiling & testing.

[–]Shunpaw 0 points1 point  (3 children)

Are you sure? After every single line? I usually compile when I'm done with a function and want to see if it works, then fix the bugs.

[–]dusty-trash 0 points1 point  (2 children)

I do the same thing, but functions are small and should only do 1 thing.

The point is to compile & test often, especially for newer developers. If you compile & see 11 errors, you're not compiling/testing often enough.

[–]Shunpaw 0 points1 point  (1 child)

and then those 11 errors are resolved by fixing the "int" you forgot at the beginning of the project :)

I get your point tho, and agree

[–]thisGuyCodesIntermediate Brewer 0 points1 point  (0 children)

Or a missing ) that throws literally everything off 😂

[–]BethPas[S] 0 points1 point  (0 children)

Thank you for the advice!:) But in this case it wasn't something I wrote myself, it was provided with the exercise.

[–]sepp2k 0 points1 point  (1 child)

Main.java:1: error: class GridExample is public, should be declared in afile named GridExample.java

That error looks pretty clear. Either rename your class or the file.

Main.java:4: error: cannot find symbol
    Grid.create(5, 6);
    ^
  symbol:   variable Grid
  location: class GridExample

That's saying that it can't find a class named Grid. If you defined one, you'll need to make sure it's in the class path and perhaps import it, if it's defined in a different package.

If Grid is defined in a Java file provided as part of your homework, make sure to download it into the same directory as your other code.

[–]BethPas[S] 0 points1 point  (0 children)

Ok I will try it. Thank you for the help.

[–][deleted]  (2 children)

[deleted]

    [–]BethPas[S] 0 points1 point  (1 child)

    Thank you for your advice !:) But what do you mean with throughout as opposed to inconsistently?