Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:42:53+00:00 2026-06-13T11:42:53+00:00

I am creating a j2me application which is interacting with a database on a

  • 0

I am creating a j2me application which is interacting with a database on a server. Therefore I launch a thread to connect to the server. I handle all my command actions in a separate class which implements CommandListener.

When I try to get the response the server returned I get an empty String. I have tried waiting for the thread that connects to the server to return but this makes the application unresponsive.

Below is the code I am using.

//my network worker class.
public class NetworkConnector implements Runnable {
    //constructor
    public NetworkConnector(String url){
       //url =>server url to connect to.
       Thread thread = new Thread(this);
       thread.start();
    }

    private String serverReply="";
    private String url="

    //method to connect to the server and return the 
    //response from the server.
    public String sendData(String serverUrl) {

      //open streams to connect to the Server.
      httpConn = (HttpConnection)  
      Connector.open(serverUrl,Connector.READ_WRITE, true);
      httpConn.setRequestMethod(HttpConnection.GET);

      inStream = httpConn.openInputStream();
      int read;
      while ((read = inStream.read()) != -1) {
        sb.append((char) read);
      }

      return sb.toString();
   }


   public String getServerReply() {
     //serverReply is a class variable.
     return serverReply;
   }

   public void run(){
      //call the send method that connects to the server.
       serverResponse = sendData(Url);
   }

} //end of connector class.

// this class is where all my Command Actions are
//implemented. 
public class CommandActionController implements
CommandListener, DataReceiver {

public void commandAction(Command cmd, Displayable d) {
   //networkMgr => is the worker class that makes
   //connection to the server.
   networkMgr = new NetworkConnector("http://localhost
   /JsonPhp/login.php?uname=" + loginUserInfo.userName +
   "&passwd=" + loginUserInfo.password);

   //here am getting the response from the server.
   String serverResponse = networkMgr.getServerReply();

   //at this point the ServerReponse String is Empty =>
   //yet the server is supposed to return some String.
   System.out.println("xxxxxxxxxxxxxxxxxx
   ServerResponse =" + serverResponse);
   }

   }//end of CommandListener class.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:42:54+00:00Added an answer on June 13, 2026 at 11:42 am

    Your expectations about serverResponse value are wrong; it can be empty at the moment when you attempt to obtain it in commandAction with the code snippet in the question.

    In order to get non-empty value, you need to redesign method NetworkConnector.getServerReply() to make it properly wait until thread finishes and server response is indeed obtained.

    If you do that, however, you will also have to redesign CommandActionController to keep user interface responsive – your testing with “waiting for the thread that connects to the server” has shown just that.

    Redesigned code should just launch the server connect thread and exit the commandAction as soon as possible (possibly changing to some “wait screen” to let user see what happens). Next screen update should be triggered only after server response is obtained.

    Consider studying a tutorial specifically targeted on explaining how to properly design this kind applications – Networking, User Experience, and Threads:

    This article explains how your MIDlet can make network connections without compromising your user interface. It includes six iterative examples that illustrate multithreaded networking and the use of a wait screen…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i am creating a J2ME application in which i need to call a
I am creating a mobile application using j2me, which interacts with a webservice. The
I am creating an application in J2ME. I have one Loginpage and SearchingAccount Page.
I'm creating an application that is supposed to read text from mySql database using
I'm creating a mobile app with j2me. My configuration is CLDC-1.1, MIDP-2.0. I'm sending
Creating a server-side socket will fail if I'm trying to use the same port
The Google Market offers an application purporting to run J2ME MIDP applications on the
How do I iterate through all recordstore for a j2me app? The recordstore are
Creating a web mapping application in Javascript/Dojo: When I load the app in a
Creating a mini-database with access, i came across this problem: For the background, i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.