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 7550281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:10:19+00:00 2026-05-30T10:10:19+00:00

i m getting a nullpointer exception continuously but i can’t figure out where the

  • 0

i m getting a nullpointer exception continuously but i can’t figure out where the problem is.
Please help.
it is a java code for client on android. i m trying to send and receive data simultaneously but it is not working.
<

package com.chat.clientone;
import android.app.Activity;
import android.os.Bundle;
import java.io.*;
 import java.net.*;

import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.KeyEvent;
import android.widget.*;

 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.IOException;
  import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
  import java.net.Socket;
 import java.net.UnknownHostException;


 import android.text.Html;
 import android.widget.Button;
 import android.widget.TextView;
 import android.widget.EditText;
 import android.util.*;

 public class ClientoneActivity extends Activity {

public static final String SERVER_HOSTNAME = "10.0.2.2";
public static final int SERVER_PORT = 3000;
private TextView tv=null;
private EditText et=null;
private Button bt=null;
private Socket socket;
BufferedReader in=null;
PrintWriter out=null;
String messageOut=null, messageIn=null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);                 
    tv=(TextView)findViewById(R.id.clienttext);
    et=(EditText)findViewById(R.id.clientedit);
    bt=(Button)findViewById(R.id.cbtn);


   try {          
           socket = new Socket(SERVER_HOSTNAME, SERVER_PORT);

           tv.append("Connected to server " +
                   SERVER_HOSTNAME + ":" + SERVER_PORT);
           et.append("Enter Username");

        }catch (UnknownHostException e1) {
         e1.printStackTrace();
        } catch (IOException e1) {
         e1.printStackTrace();
        }


            try {
                 in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                 tv.append("NOTE: Enter 'quit' to end the program.\n");
                 while (true) {
                    //System.out.print("SEND:      ");
                    messageOut = et.getText().toString()+System.getProperty("line.separator");
                   Log.e("LOG_TAG", "ERRRRRRRROOORRR"+messageOut);
                    if (messageOut.equalsIgnoreCase("quit"))  {
                          // User wants to quit.  Inform the other side
                          // of the connection, then close the connection.
                       out.println("CLOSE");
                       out.flush();
                    //   connection.close();
                       tv.append("Connection closed.");
                   //    finish();
                       System.exit(0);
                       break;
                    }
                    out.println(messageOut);
                    out.flush();
                    if (out.checkError()) {
                       throw new IOException("Error occurred while transmitting message.");
                    }
                    tv.append("WAITING...");
                    messageIn = in.readLine();
                    if (messageIn.length() > 0) {
                            // The first character of the message is a command. If 
                            // the command is CLOSE, then the connection is closed.  
                            // Otherwise, remove the command character from the 
                            // message and procede.
                       if (messageIn.equalsIgnoreCase("CLOSE")) {
                          tv.append("Connection closed at other end.");
                         // connection.close();
                     //     finish();
                          System.exit(0);
                          break;
                       }

                    }
                    tv.append("RECEIVED:  " + messageIn);
                 }
              }
              catch (Exception e) {
                 tv.append("Sorry, an error has occurred.  Connection lost.");
                 tv.append(e.toString());
                 System.out.println(e);
                 Log.e("LOG_TAG", "ERRRRRRRROOORRR"+e.toString());
                 System.exit(1);
              }


}

}

  • 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-05-30T10:10:20+00:00Added an answer on May 30, 2026 at 10:10 am

    Initialize out with BufferWriter.

    out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping you guys can figure out why im getting a null pointer exception with
I'm getting a nullpointer exception in the following code in my application : @Override
I am creating a dynamic array of buttons, but i am getting Nullpointer Exception.
Below is the code I am trying to test, but getting null pointer exception
i am writing code for btree algorithms. i am getting NullPointerException . why???? please
When I call this constructor to parse some JSON I'm getting a nullpointer exception
Can some one please assist me in this example of TabHost? The problem i
I am having trouble determining why my code gets a nullPointer exception. I'm trying
I try in following way but I am getting Null Pointer Exception at iv.setImageBitmap(bm).
I am trying to implement a linked tree but I am getting a nullpointer

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.