Cant return text from class

Hi guys,
I'm hopeing someone out there can help me out with a problem that has been bothering me for the last few days. Basically I can not get my class to return any text at all by calling the appropriate function, yet if I do a system.out.println() from within the class its self the text will be outputed to the console without a problem.
Below is the threaded class I want to retrieve the text from:
import java.io.*;
import java.net.*;
import java.util.*;
public class SockThread implements Runnable{
     private String chatter;
     public String chatText;
     private String charText;
     private Thread runner;
     private Socket socktest;
     private PrintStream out;
     private BufferedReader in;
     public SockThread() {
          if (runner == null) {
               runner = new Thread(this);
               runner.start();
     public void run() {
          try {
               this.connect();
          } catch (IOException ioe) {
     public void connect() throws java.io.IOException{
          String hostname = "efnet.xs4all.nl";
          int portnumber = 6669;
          this.socktest = new Socket(hostname, portnumber);
          this.out = new PrintStream(this.socktest.getOutputStream());
         this.in = new BufferedReader(new InputStreamReader(this.socktest.getInputStream()));
          this.out.print("user "+ "strangename" + " stranger irc : " + "Stranger");
          this.out.print("\n");
          this.out.print("nick " + "Shadwick");
          this.out.print("\n");
          Boolean eof = false;
               try {
                    while (!eof) {
                         this.charText = in.readLine();
                              if (this.charText == null){
                                   eof = true;
                                   socktest.close();
                              } else {
                                   this.chatText = charText;
          } catch (IOException ioe) {
               System.out.println("Its not working :( " + ioe);
     public void showStatus() {
          System.out.println(this.chatText);
}And here is my main class:
public class ChatConsole {
     public static void main(String[] arguments) {
          SockThread st = new SockThread();
          st.showStatus();
}No matter if i try accessing the text via the showStatus() function or directly access the chatText variable i get nothing. I'm pretty sure i'm missing something thats stopping me from getting the text but I just cant see it. If anyone can help I'd greatly appreciate it.

As you are creating another thread with the SockThread class, it runs independently from the main thread. So the SockThread Thread has probably not gotten to the part where it initiates the chatText var by the time the main thread calls the showStatus() method.
To varify this, either do:
put System.out.println("TEST"); in the show status method. If this prints then the var just hasnt been initiated yet.
OR
Use Thread.Sleep(2000); in the main method to make is sleep for a while to give the SocketThread Thread a chance to initiate the var.

Similar Messages

  • I cant receive text from ppl that have iphone sine i got andriod

    i cant receive text from ppl in my contact that have iphone very frustated

    Follow this article: iOS: Deactivating iMessage - Support - Apple
    If that doesn't work, contact Apple Support who can revoke the iMessage/Facetime certificate from association to your phone number.
    Also:
    1) Go to www.icloud.com and remove the device from Find My iPhone.
    2) Go to appleid.apple.com and change the primary email address of your Apple ID to something different (per Apple ID: Changing your Apple ID).
    3) Also at appleid.apple.com, change the password to your Apple ID (per Apple ID: Changing your password).
    4) Have any iPhone user attempting to send you a text message do the following:
    4a) Verify that in Settings > Messages that if iMessage is turned on to ensure that ‘Send as SMS’ is also turned on.
    4b) Delete the existing message thread, if any.
    4c) Delete your contact and readd, using only the phone number (no email).
    4d) Attempt to send a new text message to you.

  • HT1937 How do I get my iMessage taken off if I no longer have an iPhone? Because I cant receive texts from iPhone users.

    How do I get my iMessage taken off if I no longer have an iPhone? Because I cant receive texts from iPhone users.

    Deactivating iMessage

  • Iphone 5 broke switched to old iphone 4 but cant get texts from other iphone users cant do anything with iphone 5 like i said its wayy broke

    IPhone 5 broke switched to old iPhone 4 but cant receive texts from other iPhone users cant do anything with iPhone 5 screen does not work

    I'm guessing that you turned off the iPhone 5? If so, then are you using the same phone number as the 5? You need to go into Settings>Messages>make sure that iMessage is turned on and activated. Then go the Send & Receive and find out if your current number is checked.

  • I just got an iphone 6 plus and I cant receive texts from android or nokia users??

    I just got an iphone 6 plus and I cant receive texts from android or nokia users??
    I previously had a iphone 4s and iphone 5. Set up my phone as a brand new phone and I cant receive any texts from any of my friends that have android or nokia users and cant receive pictures from them also. Its very frustrating...does anyone have any fixes of solutions to this???

    SMS is a carrier feature. Start by contacting your carrier and making sure your account is properly configured. Even if it was before, sometimes changing phones causes glitches.

  • Got the galaxy s5 and cant receive texts from people using iphone 5

    ive had my phone for over two weeks and cant receive texts from people using iphone 5

        Gloverbug,
    We can help you get messages from iPhone users again! Please follow these steps http://vz.to/JLI4pm to deactivate your Apple ID, wait ten minutes, and then test.
    SarahO_VZW
    Follow us on Twitter @VZWSupport

  • Samsungs4 cant receive text from iphone

    ive just switch from a iphone 4 to a samsung s4. now i cant receive text from iphone users what can i do?

    Asked and answered dozens of times.  See the "more like this" section on the right side of this page and search before posting.

  • Cant send text from my iphone4s to a non iphone

    I cant send texts to a non iphone from my 4s, get message tp  resend using 10 digit number or valid short code. msg 2114 I am using 10 digits and have tried 7 digits

    Contact your carrier. SMS is a carrier function and they would be the one that would be providing the error. Have them make sure your account is provisioned correctly for SMS. You might also want to double-check your settings for Dial Assist.

  • I used to have an iphone 4 but recently switched to a galaxy but now cant recieve texts from iphone users

    i recently got a galaxy but used to have an iphone 4 but now i cant receive text messages from iphone users, the messages are still coming in as imessages.

    You can try resetting the password for the Apple ID you were using for iMessage by going to https://iforgot.apple.com/.  If that doesn't work, you'll have to contacct Apple support for assistance.

  • Am i the only one who cant recieve texts from non iphone 4 or 4s users?

    i've had issues recieving texts from ppl who dont have an iphone 4 or better. i have at&t and the two ppl i can text both have iphone 4. ppl have be get'n my text but i cant get their replys. Plz help!

    i have the exact same problem, got my iphone 4s on saturday and still won't let me send texts ._.

  • I changed to an android and now cant get text from some iphone users any suggestions??

    I have just switched to an android and now am having problems getting text from some iphone users, and suggestions as to how I can fix this?

    Hi mango72860,
    Thanks for visiting Apple Support Communities.
    If you're not receiving text messages from iPhone users, see this article for help:
    iOS: Deactivating iMessage
    http://support.apple.com/kb/TS5185
    Best Regards,
    Jeremy

  • Have iphone5s-unless I am in wifi, I cant receive texts from other iphone users unless their imessage is turned off. Help

    If in wifi zone I have no problems as the imessage to immesage works.  However, when wifi off and cellular data on I cannot recieve texts from an iphone user unless their immessage is turned off.  These iphone uses recieve my messages but I do not recieve the replies.  Help?

    Under Settings>Messages>
    Make sure Send as SMS is on . If it is on and the error still occurs go to Send and Recieve, and make sure your phone number is the ONLY thing listed.

  • Cant send texts from ipad because I don't want it linked to my iphone

    I have an ipad 3rd gen that is a personal device.  I also have an iphone 4 that is a device provided to me by my employer. i want to be able to send and receive texts from both devices, but I do not want texts from one to show up on the other and vice versa.  I have only one apple id, and would prefer to keep it that way.  How do i set this up, because I believe that my inability to do so is resulting in me not being able to send/receive texts on my ipad.

    You can't do what you are attempting to do with a single AppleID.
    The iPad can only send messages through iMessages - it is not able to send or receive traditional text (SMS) messages. So, even if you were to use it you could only receive messages from other Apple devices using Messages.

  • HT201274 i cant receive texts from iphone users

    i recently changed from an iphone 5 to a galaxy note III and i do not receive text messages from iphone users how do i delete my old device from my account so that i can receive texts from iphones

    find my iphone and imessage are two different things.
    You would've had to go to setttings - message - imessage - off

  • Cant receive texts from o2 (im on orange)

    hello im hoping you guys can help me out ! im on orange with iphone4 and for the past 3days i can send texts to people on the o2 network but no one from the o2 network can reply to me...ive contacted orange they say they sent me a sim update (whatever that might be) but i havent received that either...i can receive texts from every other network but just not o2! ive reset to factory settings i just really dont have a clue what else i can try any help would be fabulous!! thanks marie !

    Hi
    I'm having exactly the same problem. However I'm on O2. I recently migrated my number from vodafone to O2 and since joining the network I've been unable to receive any texts from O2 customers. All other services are normal i.e can receive and make calls with anyone, and send texts to anyone as well. The only issue is receving texts from other O2 users. They are infact unable to send me the texts. An error message comes up their phone when attempting. Very frustrating! Anyone care to shed some light on the situation?

Maybe you are looking for

  • How do I create a High Quality Image with a low file size???

    Dear All, I am creating an invitation in Illustrator which I then place into photshop to create a JPEG. I want to create a high quality JPEG version of it but with a low file size because I am emailing the invitation. Am I correct in placing the imag

  • Query on view

    Hi, Is it possible to fetch the records from view. like select * from [view name} where lifnr in s_lifnr. is it fine??

  • Os lion or lion server ?

    I would like to purchase a mac mini with 8Go Ram, 1TB harddisk and i7 processor. Difference of price between mac mini and mac mini server equiped by os lion server makes me asking if i should not purchase a mac mini server instead of mac mini. But wh

  • Only Right Headphone Works

    It started almost right after I listened to a song where there was a part where all of the noise would go from left and then right. It was supposed to do that, but then, within the next 10-15 minutes, the left one stopped playing any music at all. I

  • HELP!!!  math.random() problem

    Hello, I was wondering if anyone can help me with a problem I'm running into using the math.random(). I'm using Flash CS3 and created a very simple script to select random frames in a simple movie. It works as expected in the CS3 environment and in S