a question to girionis

Posted on 2003-03-12
Medium Priority
Last Modified: 2011-08-18

hi i have a client server application.
in the server side i have two buttons(3 textfileds), and on the client side have just 4 textfileds
to recive data from server.

the problem is that i can't get the data on the other side by pressing the check button(second one)!!!

here is the code from the server program:

public void actionPerformed(ActionEvent e) {
   if(e.getSource() == send){ // send is a button
       if(e.getSource() ==  check){ //check is a button

the first 3 lines sent (when send button pressed) should be displayed in three textfields(result1,result2,result3) and its working well.
the forth line sent (when the check button pressed) should be displayed in the checkResult in the client GUI which is not working.

here is the client codes witch display those lines:

 s = new Socket("", 1024);
 br = new BufferedReader(new InputStreamReader(s.getInputStream()));
       ps = new PrintWriter(s.getOutputStream(), true);      
       line = new String(); // Line to be read from the server
       line2 = new String(); // another Line to be read from the server
       line3 = new String();// another Line to be read from the server

// While there is more data coming... // this is working well when send button pressed!
while ( (line = br.readLine()) != null &&
(line2 = br.readLine()) != null &&
(line3 = br.readLine()) != null)
    // putting the incomming line from the
    // server into the result fields.
  line4 = new String(); // here is the problem why it can't display data into checkResult field when the check button pressed?!!
   while ( (line4 = br.readLine()) != null){


catch(IOException iExc){}

hope its clear.

Question by:Sharabi
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 35

Accepted Solution

girionis earned 75 total points
ID: 8126876
 Are you sure that the value you assign at line4 is not null?

  And a performance tip for you. When you initialize Strings always do it with String line = ""; and not String line = new String(); since the latter for each time you do it it creates a new String and consumes memory, while the former as many times as you do it it assigns the same meory location (so you save memory) :-). So the following:

  String line1 = new String();
  String line2 = new String();
  String line3 = new String();

  will consume 3 different memory locations while the following:

  String line1 = "";
  String line2 = "";
  String line3 = "";

  will only consume one memory location and all three instances of String (lien1, line2, line3) will point to the same.
LVL 35

Expert Comment

ID: 8127132
 So what was the problem?

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month9 days, 6 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question