Results 1 to 11 of 11
  1. #1
    wilnicm is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default 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?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default 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

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default 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 **

  4. #4
    wilnicm is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default 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.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default 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.

  6. #6
    wilnicm is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default 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;
    
    }
    
    
    
    }
    Done.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default 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.

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: newbie: Issue with storing string variable and passing it to another class

    Quote Originally Posted by wilnicm View Post
    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.
    Do you often insult people for the fun of it?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    wilnicm is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: newbie: Issue with storing string variable and passing it to another class

    Quote Originally Posted by gimbal2 View Post
    Do you often insult people for the fun of it?
    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
    Quote Originally Posted by gimbal2 View Post
    But questions can be poorly asked. Posting uncompilable gibberish is a good start of a very poorly asked question.
    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.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default 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.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: newbie: Issue with storing string variable and passing it to another class

    Quote Originally Posted by wilnicm View Post
    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.
    Well good luck with that attitude. Lucky for you there are nicer people than me here who look past such behavior, I certainly do not.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 2
    Last Post: 01-08-2014, 05:09 PM
  2. Replies: 0
    Last Post: 12-21-2012, 04:09 PM
  3. Help with passing String[] from GUI class to GUI class
    By X75TIGER75X in forum New To Java
    Replies: 9
    Last Post: 05-01-2012, 06:55 PM
  4. Problem with Class String Variable
    By rollei in forum New To Java
    Replies: 2
    Last Post: 08-03-2011, 01:24 PM
  5. Replies: 8
    Last Post: 03-04-2011, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •