r/javahelp • • May 11 '20

why cant i access this object?

https://imgur.com/a/hSrKv25

so it says it cant make a static refference to a non static field. but from what i understand, its not static. i created an object called test1 if the class test and want to access the method toString from that object. but i cant. why? i looked through my other programs and its exactly the way i always did it. what did i do wrong?

0 Upvotes

4 comments sorted by

1

u/AutoModerator May 11 '20

It seems that you possibly have a screenshot of code in your post why cant i access this object? in /r/javahelp.

Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting.

  • Never submit screenshots of code instead of code text!

If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images.

If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code.

  • For small bits of code (less than 50 lines in total, single classes only),
    the default code formatter is fine
    (one blank line before the code, then 4 spaces before each line of code).

  • Pastebin for programs that consist of a single class only

  • Gist for multi-class programs, or programs that require additional files

  • Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.

  • Ideone for executable code snippets that use only the console

Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/yshows May 11 '20

you cant call a non static object on a static function, if you make the test1 static you can access it in main again, or declare the variable directly in main

1

u/kleineaxolotl May 11 '20

class Test should be capitalised

1

u/booboo268 May 11 '20

Public static String ToString(){....}