• Post Reply Bookmark Topic Watch Topic
  • New Topic

non-static method cannot be referenced from a static context

 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys i'm trying to create a basic window with some text area but i keep getting the error message

"Error:(40, 17) java: non-static method createAndShowGUI() cannot be referenced from a static context", I know what it means but I can't find a way around this problem. Could you guys take a look at my source code and let me know where i've gone wrong and how I can get this to run. Cheers in advance!

 
Tushar Goel
Ranch Hand
Posts: 931
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says to make methos "createAndShowGUI();" as static but i don't recommend it. Instead make an object inside the thread and call the method as below:


 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say create a new object inside the thread do you mean inside the method createAndShowGUI?
 
Tushar Goel
Ranch Hand
Posts: 931
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no but inside run method. Here is your updated main method:


 
Campbell Ritchie
Marshal
Posts: 52519
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is TG's code updated to exploit Java8's λ feature:-If you go through this part of the Java™ Tutorials, you will find more details in the Lambda Expressions section. Actually that section is not as easy to read as the Java™ Tutorials usually are.
 
Campbell Ritchie
Marshal
Posts: 52519
119
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers guys it runs but no text field, anyone recommend a youtube series or online resource i can check out?
 
Campbell Ritchie
Marshal
Posts: 52519
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean about no text field? Have you created a text field object? How did you add it to the display? How are you setting its text?
Please explain all those details, so we can actually help you

If you need help about text fields, I shall move you to our GUIs forum where we usually discuss such things.
 
mitchell bat
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you move it to the GUI section so we can work on it there? I'm going to ask about adding a database to it after aswell
 
Campbell Ritchie
Marshal
Posts: 52519
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already moved you to the GUIs section. Please show us exactly what the problem is, because what you told us earlier was too vague, I am afraid.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!