r/CodingHelp • • Aug 19 '21

[Java] Why do I keep getting error:cannot find symbol. Please help

Post image
53 Upvotes

23 comments sorted by

25

u/jddddddddddd Aug 19 '21

You will probably have more luck asking in r/javahelp.

I suspect you need something like,

bigSolver bs = new bigSolver();

System.out.println(bs.firstDerivative(polynom));

(or you could just remove the class wrapping firstDerivative() and just call it as a static function)

4

u/[deleted] Aug 19 '21

Thanks!

5

u/warboner52 Aug 20 '21

or you could just remove the class wrapping firstDerivative() and just call it as a static function)

A billion percent this.

10

u/jedwardsol Professional Coder Aug 19 '21

firstDerivative is a member of the bigSolver class.

In main, you don't have an instance of bigSolver

3

u/adambahm Aug 20 '21

I can't help more than some of the excellent responses, but I can offer this:

https://www.businessinsider.com/how-to-screenshot-on-windows

2

u/PaulTS22 Aug 19 '21

Make an instance of the class i.e bigSolver bs = new bigSolver(); System.out.println(bs.firstDerivative(polynom));

1

u/TzarBuba Aug 19 '21

Your comment is perfect

1

u/dinner88 Aug 20 '21

you made a class but forgot to make its object to actually use the methods made inside of it.

1

u/code_yoga Aug 20 '21

You have two option, create bigSolver instance or make firstDerivative function become static.

But, why you make firstDerivative function if it just return the String from parameter rather than directly print on your main method?

1

u/[deleted] Aug 20 '21

One thing hurts me so much tha my brain is going to explode. Why not just use PrintScreen key on your keyboard?

1

u/PapercuttingTheHell Aug 20 '21

Brackets young man

1

u/boseslg Aug 20 '21

Your are calling a class which is within another class...

1

u/elemnopq Aug 20 '21

You are using an inner class method. That’s not how you are supposed to call. Stackoverflow this shit.

1

u/[deleted] Aug 19 '21

First make your class static

public static class className

then call it's method in 'main' class like:

className.functionName()

1

u/crazyfrecs Aug 20 '21 edited Aug 20 '21

Do not listen to the people telling you to make a static class or static method.

This is what I am assuming your first experience with OOP (object oriented programming). Classes are blueprints for objects. Objects can do things or have attributes associated to them.

For example a Car. Cars have 4 wheels, cars can move forward/backward/turn, cars can turn on and off, etc.

A blue print for a car would be: class Car{ private int wheels; public string color; public void moveForward(){ ... } public void moveReverse(){ ... } ... }

That only lists as a blueprint though not instantiating one in to existence.

For a Car to do something it needs to be created/exist. To do this in Java you can provide the blueprint and make a variable that represents the existence.

Car betsy = new Car(); betsy.color = "black"; betsy.moveForward();

Created a car named betsy that is black. Then made betsy move forward.

Now getting that out of the way you have two classes (remember, blueprints) here. One is your project class where main (a static method meaning it doesn't need an object instantiated to be called/used and is a special method that is run by java) belongs to. This is your DerivativeSolver class. Another class you have here WITHIN your DerivativeSolver class is the bigSolver class. You used the naming convention for a method though.

To use methods that aren't static, you need an instance of a class it belongs to. Using the car example: moveForward();

That does nothing because WHAT car? WHICH car? WHO?

Where as: Car betsy = new Car(); betsy.moveForward();

Car rustBucket = new Car(); rustBucket.moveReverse();

rustBucket is moving in Reverse while betsy moves forward. Both are Cars but both their own cars.

The question I have for you is: why is the method that solves the polynomial belonging to a nested class? Why is there a class within a class? That's for you to research because while i can go in to detail why that's a weird or off design choice this would be an essay.

Essentially you: A. Cant call a NON STATIC method from another class without an instance of that class. EVEN if the class the method you're calling belongs to is defined within the same class. B. Weird design choices: class within a class instead of a static method or external class, etc. For you to personally research more into. Suggestion: because it seems to be a utility method (not one reliant on attributes of a class or instance) you should just make it a static method of the DetivativeSolver class and completely dispose of your bigSolver class. C. If you choose to make the method within the DerivativeSolver class be aware that main is static and will NOT be able to call NON STATIC methods of the same class. This could be solved by making it a static method.

1

u/General_Doom_101 Advanced Coder Sep 01 '21

Looks a little too much for a beginner eh?

1

u/crazyfrecs Sep 01 '21

No I tutor/teach quite often and the sooner someone is exposed to concepts even if its through reading, the easier it is on them for preventing mistakes or developing bad habits.

1

u/General_Doom_101 Advanced Coder Sep 01 '21

Not bad fundamentals

0

u/crazyfrecs Sep 01 '21

There are no bad fundamentals in my explanation. Everything here is the bare minimum fundamentals to allow them to know what to search up to look more in to/understand while also providing a few little snippets of how objects/classes work and how to call methods.

1

u/General_Doom_101 Advanced Coder Sep 01 '21

Not bad = good I didnt called it bad

1

u/crazyfrecs Sep 01 '21

Oh okay sorry I misunderstood.

0

u/[deleted] Aug 19 '21

[deleted]

1

u/[deleted] Aug 19 '21

Just where I had clicked lol

0

u/[deleted] Aug 19 '21

[deleted]

4

u/Nightcorex_ Aug 19 '21

There was no mistake with that. He just clicked there and had the blinking cursor. The mistake was that he tried to call a method inside an inner class, without creating an instance of said inner class beforehand.