So I was making a very basic program in java and this happened:
Exception in thread "main" java.lang.ClassNotFoundException: Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Here is my "program"
public class GUI{
private JTextArea usernameInput;
private JTextArea licenceKeyOutput;
private JButton generateLicenceKeyButton;
private JPanel root;
private JPanel mainGUI;
public static void main(String[] args) {
JFrame frame = new JFrame("GUI");
frame.setContentPane(new GUI().mainGUI);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public GUI() {
generateLicenceKeyButton.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
if(usernameInput.getText() == ""){
System.err.println("[IntelliGen] Invalid username received, telling user");
usernameInput.setText("Invalid Username");
licenceKeyOutput.setText("Invalid Username");
}else{
}
}
});
}
NOTE: I made this program with IntelliJ Idea's GUI Creator.
It seems that the JDK is corrupted, but it works fine with other programs. Can you guys help me in any way?
In your IntelliJ's launcher configuration Main class is set to Main which is invalid, in this case your Main class is GUI
Run > Edit Configuration > Main class:
Exception in thread "main" java.lang.ClassNotFoundException: Main
This means you are trying to run a class named main, but your class is named GUI
Related
I am trying to render a sketch with IntelliJ however when I select the P3D renderer mode, the program throws an error. I assume it has something to do with OpenGL, but I cant find anything about it online. Code is below.
import processing.core.PApplet;
public class GUI extends PApplet {
public GUI() {
}
public void settings() {
System.setProperty("jogl.disable.openglcore", "false");
fullScreen(P3D);
}
public void draw() {
background(0);
ellipse(mouseX, mouseY, 20, 20);
}
public static void main(String... args) {
PApplet.main("GUI");
}
}
The error is
java.lang.NoClassDefFoundError: com/jogamp/opengl/GLException
at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:717)
at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:569)
at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:35)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:483)
at processing.core.PApplet.makeGraphics(PApplet.java:1932)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2011)
at processing.core.PApplet.initSurface(PApplet.java:10260)
at processing.core.PApplet.runSketch(PApplet.java:10221)
at processing.core.PApplet.main(PApplet.java:9997)
at processing.core.PApplet.main(PApplet.java:9979)
at GUI.main(GUI.java:20)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
java.lang.RuntimeException: com/jogamp/opengl/GLException
at processing.core.PApplet.makeGraphics(PApplet.java:1965)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2011)
at processing.core.PApplet.initSurface(PApplet.java:10260)
at processing.core.PApplet.runSketch(PApplet.java:10221)
at processing.core.PApplet.main(PApplet.java:9997)
at processing.core.PApplet.main(PApplet.java:9979)
at GUI.main(GUI.java:20)
Process finished with exit code 1
Thanks - any help is appreciated!
I have a base and sub class. The requirement is to invoke sub class' method using reflection. Both programs are below.
base.java
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
public class base {
public static void main(String[] args) {
URLClassLoader loader = null;
Class<?> cls;
try {
File file = new File("sub.jar" );
URL[] urls = { file.toURI().toURL() };
loader = new URLClassLoader(urls);
cls = loader.loadClass("sub");
base obj = (base) cls.newInstance();
obj.print();
}
catch(Exception e) {
System.out.println("Exception occured:" + e);
e.printStackTrace();
}
}
public void print() {
System.out.println("In Base class");
}
}
sub.java
public class sub extends base {
public void print() {
System.out.println("In subclass");
}
}
compile both in to jars.
javac base.java;
jar cvf base.jar base.class
javac sub.java;
jar cvf sub.jar sub.class
If I invoke the base.jar as "java -cp", it works fine
java -cp base.jar base
output: "In subclass"
But if I invoke it with "hadoop jar" command, I get
hadoop jar base.jar base
Exception in thread "main" java.lang.NoClassDefFoundError: base
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at base.main(base.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.lang.ClassNotFoundException: base
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Any help is greatly appreciated.
I believe your issue is on line 15 where you try to case the loader as your base class. I believe the compiler doesn't know how to handle that. Additionally, I'm not sure why you're trying to run this program with Hadoop since it does not have any of the hadoop implementations or classes
The problem is solved by placing base.jar in hadoop classpath. Run "hadoop classpath" command which lists all classpath dirs. Place the jar in one of these directories.
I added a SWT window to my project as
public class swtUI {
protected Shell shell;
protected Display display;
public static void launch() {
try {
swtUI window = new swtUI();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
// create all controls
blablabal
}
}
and call it in main() as
public static void main(String[] args) {
swtUI.launch();
System.out.println("\nComplete");
}
No problem running on Linux.
But when I replace the linux swt.jar with maxos swt.jar and run on mac, I got exception:
***WARNING: Display must be created on main thread due to Cocoa restrictions.
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Display.error(Unknown Source)
at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
at org.eclipse.swt.widgets.Display.create(Unknown Source)
at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.getDefault(Unknown Source)
at edu.rockefeller.casanovaLab.csvCheck.CsvSuiteGUI.open(CsvSuiteGUI.java:129)
at edu.rockefeller.casanovaLab.csvCheck.CsvSuiteGUI.launch(CsvSuiteGUI.java:119)
at edu.rockefeller.casanovaLab.csvCheck.Program.main(Program.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
I am pretty new to SWT. How should I change my code to make it work on mac?
Thanks
Seems this is mentioned in this FAQ. From the same link:
To work around this problem you'll have to pass the -XstartOnFirstThread option to the java executable as follows:
java -XstartOnFirstThread -cp swt.jar:. ControlExample
I'm trying to run Processing from Eclipse but whenever I run the application as a Java Application I get java.lang.ClassNotFoundException.
Here's my full code:
import processing.core.PApplet;
public class App extends PApplet {
public void setup() {
size(200,200);
background(0);
}
public void draw() {
stroke(255);
if (mousePressed) {
line(mouseX,mouseY,pmouseX,pmouseY);
}
}
public static void main(String args[]) {
PApplet.main(new String[] { "--present", "App" });
}
}
Exception:
java.lang.ClassNotFoundException: App
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at processing.core.PApplet.main(PApplet.java:6522)
at com.WordClouds.App.main(App.java:17)
I had the same problem with the class name correctly set and also the package. This solved my issue:
PApplet.main(new String[] { "--present", MyProcessingSketch.class.getName() });
You are probably doing this tuturial : http://www.learningprocessing.com/tutorials/processing-in-eclipse/
You probably overlooked this :
public static void main(String args[]) {
PApplet.main(new String[] { "--present", "MyProcessingSketch" });
}
Note that the String “MyProcessingSketch” must match the name of your class (and if it is in a package, should include the package, i.e. packagename.MyProcessingSketch).
I am trying to build a simple gui program. Everything worked well because I tested the classes before adding some GUI components such as in SWING and AWT. However when I tried some input and press the submit button it gives me this error.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.simpleAccountEntry.SimpleAccountListener.actionPerformed(SimpleAccountListener.java:15)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6389)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3268)
at java.awt.Component.processEvent(Component.java:6154)
at java.awt.Container.processEvent(Container.java:2045)
at java.awt.Component.dispatchEventImpl(Component.java:4750)
at java.awt.Container.dispatchEventImpl(Container.java:2103)
at java.awt.Component.dispatchEvent(Component.java:4576)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4633)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4297)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4227)
at java.awt.Container.dispatchEventImpl(Container.java:2089)
at java.awt.Window.dispatchEventImpl(Window.java:2518)
at java.awt.Component.dispatchEvent(Component.java:4576)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
at java.awt.EventQueue.access$400(EventQueue.java:96)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.awt.EventQueue$2.run(EventQueue.java:629)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:116)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.awt.EventQueue$3.run(EventQueue.java:643)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
I tried to debug it since yesterday but I couldn't find where I made a mistake. I tried to check this error code:
com.simpleAccountEntry.SimpleAccountListener.actionPerformed(SimpleAccountListener.java:15)
and it points to this class:
public class SimpleAccountListener implements ActionListener{
private SimpleAccountActionsPanel listen;
public SimpleAccountListener(SimpleAccountActionsPanel functionPanel){
listen = functionPanel;
}
public void actionPerformed(ActionEvent e){
listen.recordPatient(); //SimpleAccountListener.java: 15
}
}
listen.recordPatient() can be found in this class along with other methods I have written
EDIT
public class SimpleAccountActionsPanel extends JPanel{
private SimpleAccountPanel account = new SimpleAccountPanel();
**//Initialize this line
static private SimpleAccountActionsPanel perform = new SimpleAccountActionsPanel();**
private DetailsEntry<Details> setPatient = new DetailsEntry<Details>();
static private JButton submit;
static private JButton delete;
public SimpleAccountActionsPanel(){
this.setLayout(new GridLayout(1,2));
submit = new JButton("Submit Entries");
delete = new JButton("Delete Entries");
submit.setBackground(Color.DARK_GRAY);
submit.setForeground(Color.ORANGE);
delete.setBackground(Color.DARK_GRAY);
delete.setForeground(Color.ORANGE);
this.add(submit);
this.add(delete);
//SimpleAccountPanel varFields = new SimpleAccountPanel();
SimpleAccountListener performFn = new SimpleAccountListener(perform);
submit.addActionListener(performFn);
}
public void recordPatient(){
String name = account.getEnterName().getText();
String dob = account.getEnterDOB().getText();
String doc = account.getEnterDr().getText();
String allergy = account.getAllergies().getText();
String room = account.getEnterRoomNo().getText();
int convRoom = Integer.parseInt(room);
setPatient.addEntry(new Details(name, dob, doc, allergy, convRoom));
}
}
Anyone care to help me out? If you need more of the classses I implemented I can post it just let me know Thanks in advance.
EDIT
Thanks to Max and MadProgrammer I initialized perform as suggested program now works perfectly.
You're passing SimpleAccountListener a reference to the variable perform which isn't initialised in the constructor of SimpleAccountActionsPanel, hence the NPE
SimpleAccountListener performFn = new SimpleAccountListener(perform); // <-- perform is not initialised...
I'm trying to figure out why you didn't just pass this?
SimpleAccountListener performFn = new SimpleAccountListener(this);
You have this declaration:
private SimpleAccountActionsPanel perform;
But perform is never initialized, it is null, hence NullPointerException. You're passing it to SimpleAccountListener.