Reputation: 1
I am currently doing a project in my first java class. This is my first semester coding java and I am a C++ main so it has been kind of difficult picking things up. The main issue I am currently having is that for whatever reason my main file won't recognize the methods that I implemented in my class file.
The main file is called Main.java and it header is as follows:
package com.auda;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.awt.*;
The header for my methods file is as follows:
package com.auda
import javafx.scene.canvas.GraphicsContext
import java.awt.*;
import java.awt.*;
The errors I'm getting are as follows:
symbol: class MyShape location: class Main Main.java:20: error: cannot find symbol MyShape s1 = new MyShape(1000, 700, Color.green); I got 34 of these errors, all for methods in my method file.
The entirety of my code is https://i.sstatic.net/V9bKR.jpg
Basically the compiler refuses to recognize the methods in my class file. Sorry if this is poorly formatted. I don't have the tenure on this platform to post pictures of my code and I don't want to post a bunch of pages of code.
Upvotes: 0
Views: 369
Reputation: 171
Randy's answer is right, but it won't cause the error message you are getting (you'll get MyShape is Abstract; cannot be instantiated
). Your message has occurred because the compiler can't find the MyShape class.
Your imports should work the file structure of your project is something like this:
If you have any other folders, for example if Shapes.java is in java/com/auda/shapes/Shapes.java you will run into issues. In this case, you would need to change the package for Shapes.java to com.auda.shapes and import the classes you wish to use using import com.auda.shapes.MyShape
or import com.auda.shapes.*
.
However, only one of the shape classes you posted was public. The other classes you have written will have default visibility and can't be used outside of their package (see https://www.baeldung.com/java-access-modifiers).
Upvotes: 2
Reputation: 1
Abstract class (MyShape) cannot be initiated directly from the main class, you should create a child class to implement the abstract class and use it to create the New Object.
Reference : https://beginnersbook.com/2013/05/java-abstract-class-method/ (Rules No 2)
Note 2: Abstract class cannot be instantiated which means you cannot create the object of it. To use this class, you need to create another class that extends this this class and provides the implementation of abstract methods, then you can use the object of that child class to call non-abstract methods of parent class as well as implemented methods(those that were abstract in parent but implemented in child class).
Upvotes: 0