Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

newbie question

Thread view: 
ahimsa - 14 Nov 2006 17:11 GMT
Hi all,

I am new to the language and have the following code:

public static void main(String[] args)
   {
System.out.println("Running RTSS_STD");

rtss_std sim = new rtss_std();

rtss_std.run_sim();
   }

but it gives the following error when I compile:
rtss_std.java:60: non-static method run_sim() cannot be referenced from a
static
context
       rtss_std.run_sim();
               ^
1 error

Can anyone explain what I need to do to create an object in a static func
and then use non-static objects??

TIA!
Ian Shef - 14 Nov 2006 19:09 GMT
"ahimsa" <mark.cridge@googlemail.co.uk> wrote in news:4559f8be$0$1392
$da0feed9@news.zen.co.uk:

> Hi all,
>
[quoted text clipped - 21 lines]
>
> TIA!

rtss_std is a badly named class.  If it was named according to Java
conventions, perhaps the error would stand out more.  A better name would
be:
RtssStd

The capitalization makes it clear that this is the name of a class, while
"sim" is the name of a reference variable of type RtssStd.  Then it mmight
be clear that this line:
   rtss_std.run_sim() ;

should be more like:
   sim.run_sim() ;

Of course, the method run_sim should be runSim or perhaps just "sim" to
comply with the naming conventions too.

Let us know whether this is clear or you need further explanation about
static vs non-static.

Good Luck!

Signature

Ian Shef     805/F6      *    These are my personal opinions    
Raytheon Company         *    and not those of my employer.
PO Box 11337             *
Tucson, AZ 85734-1337    *

Sean Fritz - 06 Jan 2007 08:32 GMT
> Hi all,
>
[quoted text clipped - 21 lines]
>
> TIA!

It just needs the method of RtssStd to be static:

public static type runSim()
{
  ...
}

where "type" is the type of whatever the method returns.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.