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?

5
  • you are setting your -classpath twice. Commented Apr 14, 2016 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? Commented Apr 14, 2016 at 17:19
  • You can only launch programs that have a main() method via java Commented Apr 14, 2016 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 Commented Apr 14, 2016 at 17:27
  • this could help you stackoverflow.com/questions/18802098/… Commented Apr 14, 2016 at 17:30

1 Answer 1

0

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

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

5 Comments

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)
can you show the import statements of the class
I'll add them to the original post, just need a few minutes
may be you should build your application then. and try after that
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!)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.