• Advertisement
Sign in to follow this  

Java questions - why doesnt this work [simple code]

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement