Java questions - why doesnt this work [simple code]

Started by
3 comments, last by Xer0botXer0 6 years, 10 months ago

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.

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?

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.

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.

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!

This topic is closed to new replies.

Advertisement