Jump to content
  • Advertisement
Sign in to follow this  
Xer0botXer0

Java questions - why doesnt this work [simple code]

This topic is 566 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

Hi guys,

 

Im currently doing a tutorial on java, but im getting an error

package mypkg;

public class Puppy  //my class
{
	public Puppy(String name){ //my constructor, every class has one
		
		System.out.println("Passed Name is:" + name);
	}
	
	
	public static void main(String []args){
		
		Puppy myPuppy = new Puppy( "Blue berry");
	}
	
}

Here;s the error

Exception in thread "main" java.lang.ClassNotFoundException: org.sqlite.JDBC
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at mypkg.test.main(test.java:14)

I'm not sure why this is happening ? 

Managed to answer a few of the questions ,from what I understand a .java file can only have one public class, it may have private classes too, the main there is a an inner class ? I dont see how constructor is being defined as a constructor.. does it just know ? 

Edit: I see it has got something to do with another class on the side, is there a way to only run one class ? I don't want to run the other class at the moment. 

Edited by Xer0botXer0

Share this post


Link to post
Share on other sites
Advertisement

I'm not sure why it's happening either: when I compile and run the code it outputs "Passed Name is:Blue berry" as expected. How are you compiling and running your code anyway?

Share this post


Link to post
Share on other sites

In the edit I mentioned that I see it's because of another class.

I'm wondering if I can 'run' only one class at a time, to test it. Without having to delete the other class or something.

Share this post


Link to post
Share on other sites

Well if you're running class test then it's obviously not going to run class Puppy. You don't need to delete either class to run the other class though.

Share this post


Link to post
Share on other sites

The other class was causing me problems because I was just putting it there, I suppose I could have commented it out but I ended up deleting it for now.

 

 But it was the cause of the problem so solved!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!