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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:40:09+00:00 2026-06-14T23:40:09+00:00

For class I am creating a simple client/server. The client opens a jframe, where

  • 0

For class I am creating a simple client/server. The client opens a jframe, where the user enters the host and port number. If a connection is made, another jframe is opened that has a keylistener. What is typed on the client’s side is displayed in the server’s jtextarea. I am able to make the connection between client and server, but after this I run into null pointer exception right after. I assume I should be using something else than bufferedreader in my server, or if I could stop the server from reading in until something is actually entered? Or am I doing something else completely wrong? Any help would be appreciated, and the relevant code is below.

public class TypeServer extends JPanel {

BufferedReader lnr;


public TypeServer(Socket soc) throws IOException {

    InputStream inStream = soc.getInputStream();
    InputStreamReader isr = new InputStreamReader(inStream);
    BufferedReader lnr = new BufferedReader(isr);


}
//below is in the main function
try {
        ServerSocket srv = new ServerSocket(5555);
        Socket soc=srv.accept();
        while (true) {


            // Create server
            TypeServer tc = new TypeServer(soc);
            String line=tc.lnr.readLine();
            textArea.append(line);
            srv.close();
            soc.close();

        }
    }

EDIT: I apologize for not including this before, but the
String line=tc.lnr.readLine();
line hits the null pointer exception

  • 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-14T23:40:10+00:00Added an answer on June 14, 2026 at 11:40 pm

    In your main you are using the instance variable

    String line=tc.lnr.readLine(); //lnr is not initialized
    

    You have to change the following

    BufferedReader lnr = new BufferedReader(isr); //initializing the local variable
    

    to

    this.lnr = new BufferedReader(isr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating my first, very simple RMI client-server application. Here is the code:
I'm creating simple peer to peer game. Currently I'm working on Server/Client(Node) side. I
I am creating simple web-service client in Objective-C and found that creating separate class
I am creating a simple HTTP client/server application on my local machine but I
I created a simple class to hide the details of creating a toolbar in
I'm currently creating my first android app and I've a simple class 'Player' I
I am creating a socket server in C# and a client in PHP. The
I am creating a simple application where clients need to talk to a server
While creating a simple client for a REST service which I have stubbed out,
I have a simple Sencha Touch 2.1 model class: Ext.define('App.model.User', { extend: 'Ext.data.Model', config:

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.