Results 1 to 11 of 11
- 06-25-2014, 06:47 PM #1
Member
- Join Date
- May 2014
- Posts
- 22
- Rep Power
- 0
newbie: Issue with storing string variable and passing it to another class
Hey this is a stupid question but I'm having an issue storing the variable and passing it along to another class.
I've been debugging the program and i can see that the string variable is being stored
but when i access it from my other class it is null here is the sample code.
this is an inner class
public Class exmaple {
public String str;
Public void mthd (){
somthing somethng
str = anotherstring;
getStrn (anotherstring);
}
public String getStrn(String tstr){
return str
}
}
public class anotherClass{
private vod bth {
exmaple exp = new exmaple();
String mystring = exp.str;
}
}
Well when it gets to my other class its null. While i'm debugging it in the other class where i'm setting it
I see it being set. But as soon as i leave it and go to the method in another class its null. I dont know what i'm
missing here?
- 06-25-2014, 06:53 PM #2
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: newbie: Issue with storing string variable and passing it to another class
Warning: brutal honest mode.
There are no stupid questions.
But questions can be poorly asked. Posting uncompilable gibberish is a good start of a very poorly asked question."Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 06-25-2014, 07:07 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: newbie: Issue with storing string variable and passing it to another class
When posting code please wrap it in [ code] tags [ /code].
As gimbal says, also post code that at least makes some sense.
Is this really what your getter looks like?
Java Code:public String getStrn(String tstr)
Please do not ask for code as refusal often offends.
** This space for rent **
- 06-25-2014, 07:13 PM #4
Member
- Join Date
- May 2014
- Posts
- 22
- Rep Power
- 0
Re: newbie: Issue with storing string variable and passing it to another class
lolol listen i understand you cant read gibberish since your advanced skills have retarded that part of your brain but i was asssuming someone our here in java forums land was once in my position and could read the gibberish and help me. Thats all. I was trying to be as specific and gibberish as possible.
- 06-25-2014, 08:20 PM #5
Re: newbie: Issue with storing string variable and passing it to another class
gibberish will be more readable if wrapped in code tags.
If you don't understand my response, don't ignore it, ask a question.
- 06-25-2014, 08:45 PM #6
Member
- Join Date
- May 2014
- Posts
- 22
- Rep Power
- 0
Re: newbie: Issue with storing string variable and passing it to another class
Java Code:public Class exmaple { public String str; Public void mthd (){ somthing somethng str = anotherstring; getStrn (anotherstring); } public String getStrn(String tstr){ return str } } public class anotherClass{ private vod bth { exmaple exp = new exmaple(); String mystring = exp.str; } }
- 06-25-2014, 09:01 PM #7
Re: newbie: Issue with storing string variable and passing it to another class
The code has lost all its indentations. Nested statements (within {}s ) should be indented.
What is the name of the variable?
Where in the posted code is the value of the variable set to a valid value and where is its value null?If you don't understand my response, don't ignore it, ask a question.
- 06-25-2014, 09:04 PM #8
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
- 06-26-2014, 12:38 AM #9
Member
- Join Date
- May 2014
- Posts
- 22
- Rep Power
- 0
Re: newbie: Issue with storing string variable and passing it to another class
Listen i don't go around insulting people and i'm not in any mood to insult when i'm asking for help, but i took your quote as a sly underhand diss so i responded accordingly, you took it the same way i took you writing that comment. Now getting back to
the task at hand.
What do need to post so i can get some traction to figuring out what i'm doing wrong. My code is long so i didn't want to post all the lines of code on here. I thought by posting the code you called gibberish maybe someone could undersand what i was trying to do.
In short. I'm trying to use a string that is located in another class in a different method. When the string gets to the method i'm trying to use its already null. I dont really know why its already null tried debugging it and havent really figured it out.
- 06-26-2014, 12:43 AM #10
Re: newbie: Issue with storing string variable and passing it to another class
If you think the String variable is getting set to a value (not null) make sure that the code that sets the value is called before the code that retrieves the null value. To see the order of events, Add some println() statements to print out when that happens.
If you need help, Make a small, complete program that compiles, executes and shows the problem. Without code that shows the problem, its hard to solve it.If you don't understand my response, don't ignore it, ask a question.
- 06-26-2014, 10:04 AM #11
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
Re: newbie: Issue with storing string variable and passing it to another class
"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
Similar Threads
-
error passing value of a variable from one class to main method of another class
By nischalinn in forum New To JavaReplies: 2Last Post: 01-08-2014, 06:09 PM -
problem passing a sqlite string value to another class
By dave28uk in forum AndroidReplies: 0Last Post: 12-21-2012, 05:09 PM -
Help with passing String[] from GUI class to GUI class
By X75TIGER75X in forum New To JavaReplies: 9Last Post: 05-01-2012, 07:55 PM -
Problem with Class String Variable
By rollei in forum New To JavaReplies: 2Last Post: 08-03-2011, 02:24 PM -
Assigning an existing class to a new variable (memory issue)
By chardsigkit in forum New To JavaReplies: 8Last Post: 03-04-2011, 02:50 PM
Bookmarks