Java Class/Package interaction -


I have two Kjav files that I tried to compile the javac in the OS X Terminal I am doing / P>

DieRun.java

  Die package; Public category DieRun {public static zero main (string [] args) {die d6 = new die (6); }}   

and Die.java:

  package die; Import java.util.Random; Die public category {Private Int party; Private int values; Private random RNG; Public die (int side) {This side = side; this.rng = new random (); This.value = this.roll (); } Public die (int side, int seeds) {this.sides = sides; this.rng = new random (seed); This.value = this.roll (); } Public Interval Roll () {this.value = this.rng.nextInt (this.sides) + 1; This return.value; } Public int getValue () {return.value; }}   

by javac * .java they use both compiled without any errors, but when I tried to run one of them (Eg. java dierun ) failed with this error: The main category DieRun could not be found or loaded.

If your classes designated a package "dying" to play them, you have a few options.

The quick option package is to remove the announcement so that they are in the default package. Normally not the best practice, but for the quick one-stop applications, it is perfectly valid.

The correct option is:

  1. Put your file in the subdirectory called "die"
  2. Compile them there (so that the class files in "die" Are - this is a real important part).
  3. Go to the parent directory and run java die .DieRun .

    The directory structure must match the package structure. There is a bit more about current square paths, but it will bring you on your feet.

    You may also want to read.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -