• Post Reply Bookmark Topic Watch Topic
  • New Topic

transfer a string from a not-static method to a static one?  RSS feed

 
Glenn Mause
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I transfer a String from a static method to a not-static?
I am using processing(external Software) and want to draw something from another

~Glenn
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

How do I transfer a String from a static method to a not-static?


It can't be done, because the static method has no concept of a instance, and you need an instance to call a nonstatic method.

But your subject reads: "transfer a string from a not-static method to a static one?"

That's easy. You just call the static method from the nonstatic one and pass the String.
 
Glenn Mause
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:

It can't be done, because the static method has no concept of a instance, and you need an instance to call a nonstatic method.


First sorry for messing this up, i wanted to transfer a string from a static to a non-static method.
So there is really no way to get a String in the non Static method?
Not with public variables or something?
Because the only thing i need is the String in my non-static.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code and show us what you are trying to do?
And remember to UseCodeTags <- this is a link...while posting code.
 
Glenn Mause
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if you know the "processing" "add on?"?

but as you said, heres the Code:


So thats a bit of my code.
In the draw method you have to write what should be drawn.
everytime where I wrote System.out.println the method draw somehow should draw the sentence.
So as you see draw is not-static and the "actual" Code is static.
I can't do if statements or loops in the draw so i have to do them in the Other method.
But I have to transfer the output to draw.
I hope you can help.

~Glenn
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does introduction() have to be static? If so, why?
 
Tushar Desai
Greenhorn
Posts: 5
Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is no good reason to make the introduction() method static, then you should make it an instance method. Otherwise, you can create a static variable public static RouletteProcessing useThis, initialize it to the instance of RouletteProcessing that you want to use and then invoke useThis.draw().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!