0

I'm trying to get an program that I coded to run properly. So far it will javac and java fine, however I get a NoClassDefFoundError.

This screenshot shows how I've javac, java the program, and the command prompt report. enter image description here As you can see I have 3 source files, and therefore 3 classes. PeriodicTable doesn't do anything related to the issue.

Inside of class Table I have...

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.json.JsonArray;
import javax.json.JsonObject;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Dimension;

import java.io.IOException;

class Table {
    //Predefining some global variables
    DataBaseReader dbReader;
    //some methods...
    protected void showLayout() {
        dbReader = new DataBaseReader();
        //A few lines of code
        try {
            JsonArray elements = dbReader.readDataBase(); //Here it enters the DataBaseReader class through dbReader
            //Some more code
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
    }
}

Here is my DataBaseReader class

import javax.json.Json;
import javax.json.JsonReader;
import javax.json.JsonObject;
import javax.json.JsonArray;
import java.io.FileReader;
import java.io.IOException;

public class DataBaseReader
{
public JsonArray readDataBase() throws IOException {    
    System.out.println("Check!"); //This check is reached
    JsonReader reader = Json.createReader(new FileReader("C:/projects/PeriodicTable/Elements.JSON"));
    System.out.println("Check!"); //This check is not reached
    JsonObject jsonst = reader.readObject();
    reader.close();
    return jsonst.getJsonArray("Elements"); 
}
}

What versions, programs, etc am I using?

Java 8

Command Prompt

Notepad

javax.json-1.0.jar

To clearly state my question... Any ideas or explanations about what is causing this error?

Tyler
  • 957
  • 11
  • 27
  • you are setting your `-classpath` twice. – nyname00 Apr 14 '16 at 17:15
  • CBastianelli said something that made think about that again. However, for some reason command prompt can't find the classes unless I use -classpath a second time... Any ideas on how to fix this? – Tyler Apr 14 '16 at 17:19
  • You can only launch programs that have a `main()` method via `java` – Bajal Apr 14 '16 at 17:19
  • I do have a main method, it's in PeriodicTable class. Also the program compiles and launchs, the NoClassDefFoundError appears during runtime – Tyler Apr 14 '16 at 17:27
  • this could help you http://stackoverflow.com/questions/18802098/setting-classpath-using-command-prompt-in-windows-7 – nyname00 Apr 14 '16 at 17:30

1 Answers1

0

i think you are missing javax.json-api-1.0.jar file

Priyamal
  • 2,919
  • 2
  • 25
  • 52
  • I've used javax.json-1.0.jar and have it successfully worked with previous attempts for this program. (Though for other reasons I had to scrap these attempts) – Tyler Apr 14 '16 at 17:20
  • can you show the import statements of the class – Priyamal Apr 14 '16 at 17:22
  • I'll add them to the original post, just need a few minutes – Tyler Apr 14 '16 at 17:24
  • may be you should build your application then. and try after that – Priyamal Apr 14 '16 at 17:27
  • The program doesn't reach the end of the current application though, it fails at table.showLayout(); -> JsonArray elements = dbReader.readDataBase(); -> JsonReader reader = Json.createReader(new FileReader("C:/projects/PeriodicTable/Elements.JSON")); I've already tested this, as it does not output the second 'Check!' (See the code in DataBaseReader for Check!) – Tyler Apr 14 '16 at 17:30