Jump to content
  • Advertisement
Sign in to follow this  
d1th3r

Java errors

This topic is 3672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get this error: C:\Users\mark\Desktop>java gametry.class Exception in thread "main" java.lang.NoClassDefFoundError: gametry/class Caused by: java.lang.ClassNotFoundException: gametry.class at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) Here's my source:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Gametry {
	private static void GUItry() {
		JFrame f = new JFrame("Game Window");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JLabel emptyLabel = new JLabel("");
		emptyLabel.setPreferredSize(new Dimension(800,600));
		f.getContentPane().add(emptyLabel,BorderLayout.CENTER);
		f.pack();
		f.setVisible(true);
		}
		public static void main(String args[]) {
			javax.swing.SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					GUItry();
					}
				});
			}
					public class ImageApplet extends JApplet {
		public void init() {
			Container content_pane = getContentPane();
			Image img = getImage (getCodeBase (), "Halo.jpeg");
			DrawingPanel drawing_panel = new DrawingPanel (img);
			content_pane.add (drawing_panel);
			}
		}
		}

		
		class DrawingPanel extends JPanel {
		Image img;
		DrawingPanel (Image img)
		{this.img = img; }
		public void paintComponent (Graphics g) {
		super.paintComponent (g);
		int imgX = getSize ().width/2 - img.getWidth (this);
		int imgY = getSize ().height/2 - img.getHeight (this);
		g.drawImage (img, imgX, imgY, this);
		}
	}


Please help, i'm not sure what i've done wrone. :D

Share this post


Link to post
Share on other sites
Advertisement
Hi, run it with 'java Gametry' without the .class on the end and it works fine.

Share this post


Link to post
Share on other sites
You never added an Image to your JFrame. You only added a DrawingElement to your applet class, which never runs, since you launch the "Gametry" class and not the applet.

I am confused why you have an applet and a JFrame.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!