# 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.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 on other sites

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 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 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 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!

## Create an account

Register a new account