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

  • Home
  • SEARCH
  • 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 8068593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:44:31+00:00 2026-06-05T12:44:31+00:00

I have a problem in the socket of the following code which made the

  • 0

I have a problem in the socket of the following code which made the program when I run it on AVD to stopped working (Unfortunately your -app- has stopped), I use Android 4.0 platform on Windows 7 ..
I tried to move the socket section to the button click, so when I click on the button the program stopped working, so here in the socket definition make the error. (Socket socket;)

public class ServerClient extends Activity {
// declaration of button, textView
private Button bt;
   private TextView tv;
  //port number
   private static final int REDIRECTED_SERVERPORT = 5000;
  //ip address
   private String serverIpAddress = "10.0.2.2";
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      bt = (Button) findViewById(R.id.myButton);
      tv = (TextView) findViewById(R.id.myTextView);

         // on click on the button the socket will be created
      bt.setOnClickListener(new OnClickListener() {

           Socket socket; //this line cause the app to stop working

         public void onClick(View v) {

          try {
             InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
             socket = new Socket(serverAddr, REDIRECTED_SERVERPORT);

          } catch (UnknownHostException e1) {
             e1.printStackTrace();
          } catch (IOException e1) {
             e1.printStackTrace();
          }
            try {
               EditText et = (EditText) findViewById(R.id.EditText01);
               String str = et.getText().toString();
               PrintWriter out = new PrintWriter(new BufferedWriter(
                     new OutputStreamWriter(socket.getOutputStream())),
                     true);
               out.println(str);
               Log.d("Client", "Client sent message");

            } catch (UnknownHostException e) {
               tv.setText("Error1");
               e.printStackTrace();
            } catch (IOException e) {
               tv.setText("Error2");
               e.printStackTrace();
            } catch (Exception e) {
               tv.setText("Error3");
               e.printStackTrace();
            }
         }
      });
   }
}
  • 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-05T12:44:32+00:00Added an answer on June 5, 2026 at 12:44 pm

    Hello I had the same problem (Windows 7, Android 4.03). I have solved the problem using android 2.33 (API level 10) and emulator with android 2.33 kernel.

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

Sidebar

Related Questions

Currently I have the following code, working with Node.js, socket.io and Redis: var io
I have a problem here with this code. I'm opening a socket, then listening
i have a little problem with my java socket code. I'm writing an android
i have a problem with data transfert in boost::asio. with the following code :
I have created an applet which has a necessity to execute the following code:
I have the following piece of code to listen to a port which is
I have implement the following code to create a SSL server socket. public void
I'm trying to get a multicast socket working on a 'server' app, which will
In my socket code I have the following structure: Server: #include <stdio.h> #include <stdlib.h>
I have the following code: if ( ( m_mainSocket = ::socket( PF_INET, SOCK_STREAM, IPPROTO_TCP

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.