0

I want to compile my java class like that: javac ResultSet.java

But I get the following error:

ResultSet.java:5: error: package data does not exist
import data.Spieler;
       ^
ResultSet.java:8: error: cannot find symbol
    private ArrayList<Spieler> meineSpieler = new ArrayList<Spieler>();
                      ^
symbol:   class Spieler
location: class ResultSet
ResultSet.java:12: error: cannot find symbol
    public native Spieler[] getSpieler();
                  ^
symbol:   class Spieler
location: class ResultSet
ResultSet.java:18: error: cannot find symbol
    public ArrayList<Spieler> getMeineSpieler() {
                     ^
symbol:   class Spieler
location: class ResultSet
ResultSet.java:8: error: cannot find symbol
    private ArrayList<Spieler> meineSpieler = new ArrayList<Spieler>();
                                                            ^
symbol:   class Spieler
location: class ResultSet

How can I import the spieler class? Should I set the classpath or is there a other way to fix that?

6
  • looks like a problem with teh package... check that Commented Oct 6, 2016 at 10:13
  • 1
    "Should I set the classpath ...?" - exactly, how else should the compiler know which class to import (there might be several versions on your system)? Besides that you might want to consider using a build system like Gradle or Maven to facilitate that. Commented Oct 6, 2016 at 10:13
  • 1
    also, i´d recommend to use an ide in order to not care for things you don´t really want to care for (like packages while manually compiling) Commented Oct 6, 2016 at 10:14
  • 1
    so yes, you need to add -cp <path-to-package-for-spieler> Commented Oct 6, 2016 at 10:15
  • So I should use -cp <path to class spieler> <path to class JNIResultSet> ? Commented Oct 6, 2016 at 10:16

2 Answers 2

1

Go one directory up and then compile it with

javac data/JNIResultSet.java

Update: Ok, your class JNIResultSet is in package model and it uses other classes in package data.

Then your compile command should be as follows:

javac -cp . model/JNIResultSet.java

The -cp . part means, that your classpath includes the current directory. This is the root of your package hierarchy. So the compiler can find the *.java files in package data and compiles them also as needed.

You see, this can be very complicated. For more classes this will be nearly unmanageable. So you should really consider to use a build system like Ant, Maven or Gradle.

Sign up to request clarification or add additional context in comments.

4 Comments

but JNIResultSet is in a other package then class Spieler
Ok, in what package is class Spieler? Use this path in the javac command.
I have 2 packages called data where the Spieler class is and model where the JNIResultSet class is
It is not really clear what you mean by 2 packages called data, but I updated my answer to reflect the package hierarchy.
1

use -classpath while compiling the file as
javac -classpath <path-to-dependent-classes> JNIResultSet.java

It is required only when the Spieler is not on classpath!

for more help refer javac oracle documentation

2 Comments

Sorry, I'm new at this stuff. How would my javac look like if I want to compile class JNIResultSet? My project looks like that -> src -> data package (contains person class) and model package(contains JNIResultSet)
from src folder, run javac -classpath ./ model/JNIResultSet.java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.