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?

mafioso
  • 1,630
  • 4
  • 25
  • 45
  • looks like a problem with teh package... check that – ΦXocę 웃 Пepeúpa ツ Oct 06 '16 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. – Thomas Oct 06 '16 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) – SomeJavaGuy Oct 06 '16 at 10:14
  • 1
    so yes, you need to add `-cp ` – Ash Oct 06 '16 at 10:15
  • So I should use -cp ? – mafioso Oct 06 '16 at 10:16
  • Possible duplicate of [How does javac automatically compile dependencies of a class](http://stackoverflow.com/questions/30527632/how-does-javac-automatically-compile-dependencies-of-a-class) – acm Oct 06 '16 at 10:21

2 Answers2

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.

vanje
  • 10,180
  • 2
  • 31
  • 47
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

Arjun
  • 3,248
  • 18
  • 35
  • 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)` – mafioso Oct 06 '16 at 10:23
  • 1
    from `src` folder, run **`javac -classpath ./ model/JNIResultSet.java`** – Arjun Oct 06 '16 at 10:56