![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2004
Posts: 13
Rep Power: 0
![]() |
I know this is a dumb question, but I started a class on java, and the teacher keeps telling me to wait whenever I have questions. Basicaly, im working on getting parameters to pass correctly.
public class StringTest {
public static void main(String[] args) {
System.out.print("Hello World");
kevin.outp("Hello World");
}
}public class kevin {
String s1;
void outp(String s1){
System.out.print(s1);
}
}i'm using the NetBeans IDE in a Gentoo Linux enviroment and am getting this error Exception in thread "main" java.lang.NoSuchMethodError: main for kevin.java, is the compiler attempting to find method main in the kevin class? This is more a compiler issue I think, as i think this code is identical to some i got working in class, but its been striped down tothe bare bones so i can get this to work. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
You might need to import the class kevin if it is not working. The error means in the main methind, it cant find the class it is asking for.
Or you could do:
Kevin kev = new Kevin(); //Declare an object kevin
kev.outp("Hello World"); //Use a method from that object.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#3 | |
|
Programmer
|
Quote:
__________________
David Morris BSc.(Hons), MBCS Qualified Computer Engineer Administrator (SEED Software) |
|
|
|
|
|
|
#4 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
If the two files are in the same folder, shouldn't he be able to access the method anyway, without haveing to create an instance of the class?
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#5 |
|
Programming Guru
![]() |
Dont think so just tried it on my computer with a few classes i have created and to access the methods it needs an instance of that class.
I am working in servlets and java beans as well so that might be the reason you have to do that.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity." - Albert Einstein |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Aug 2004
Posts: 13
Rep Power: 0
![]() |
Yes, the error was just a difference in JDK's and IDE's at school and home. In netbeans the new declaration is wanted/needed, good habit regaurdless. This is really my first foray into OO, so Im getting aclimatized to the differnt mindset needed, but I have to say, its much more effective, once you start to get the hang of it.
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Oct 2004
Location: Cebu, Philippines Occupation: Official Janitor SSS Contribution: 0 Pesos Certifications: None
Posts: 2
Rep Power: 0
![]() |
You can have methods member to your class and not an instance of the object. Static modifiers as they say
public class sample
{
public static void main(String[] args)
{
System.out.println("Hello World");
Kevin.outp("Hello World");
}
}
class Kevin
{
public static void outp(String s)
{
System.out.println(s);
}
} |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Aug 2004
Posts: 13
Rep Power: 0
![]() |
yeah, sorry, I forgot I posted this, I wasn't thuinking OO enough, I needed to declare the class static if i wanted to use it in this manner.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|