Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 11th, 2004, 9:25 PM   #1
qub333
Newbie
 
Join Date: Aug 2004
Posts: 13
Rep Power: 0 qub333 is on a distinguished road
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");
  }
  
}
then I have
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.
qub333 is offline   Reply With Quote
Old Sep 13th, 2004, 3:00 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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
Berto is offline   Reply With Quote
Old Sep 13th, 2004, 7:29 AM   #3
Pimp Daddy
Programmer
 
Join Date: Aug 2004
Location: Wherever the beautiful women are.
Posts: 30
Rep Power: 0 Pimp Daddy is on a distinguished road
Send a message via MSN to Pimp Daddy Send a message via Skype™ to Pimp Daddy
Quote:
Originally posted by Berto@Sep 13 2004, 08:00 AM
Or you could do:

Kevin kev = new Kevin();  //Declare an object kevin
kev.outp("Hello World");   //Use a method from that object.
Before you can use the output method, you need to create what is called an instance of the kevin class. This is done by using the constructor line, which is the first line in the above code sample. Once you've done this, you can access any of the methods in the kevin class.
__________________
David Morris BSc.(Hons), MBCS
Qualified Computer Engineer
Administrator (SEED Software)
Pimp Daddy is offline   Reply With Quote
Old Sep 13th, 2004, 3:31 PM   #4
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
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
Mjordan2nd is offline   Reply With Quote
Old Sep 14th, 2004, 3:03 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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
Berto is offline   Reply With Quote
Old Sep 14th, 2004, 6:35 PM   #6
qub333
Newbie
 
Join Date: Aug 2004
Posts: 13
Rep Power: 0 qub333 is on a distinguished road
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.
qub333 is offline   Reply With Quote
Old Oct 17th, 2004, 8:48 PM   #7
brown monkey
Newbie
 
Join Date: Oct 2004
Location: Cebu, Philippines Occupation: Official Janitor SSS Contribution: 0 Pesos Certifications: None
Posts: 2
Rep Power: 0 brown monkey is on a distinguished road
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);
  }
}
Hope I make sense.
brown monkey is offline   Reply With Quote
Old Nov 6th, 2004, 6:12 PM   #8
qub333
Newbie
 
Join Date: Aug 2004
Posts: 13
Rep Power: 0 qub333 is on a distinguished road
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.
qub333 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC