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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:57:56+00:00 2026-05-26T01:57:56+00:00

I have this structure in my program: class Node0 private Server server; … public

  • 0

I have this structure in my program:

class Node0
  private Server server;
  ...
  public void init(){
      server.waitConnections();
  ...

class Server
  socket = ss.accept(); // ss :socketServer object
  handler = new Handler(socket);
  handler.start(); // start handler thread


class Handler
  public void run() {
    while (true) {
      try {
        package = (Package) ois.readObject(); // ois :ObjectInputStream
        if (package != null) {
          this.setPackage(package);
        }
      } catch (Exception e) {
        break;
      }
  }

But now I need to get the package object in the Handler class in my Node0 class, how could I do that ? I receive the package in the Handler class, but now I should be able to send this object to my Node0 class, but if I try to get this value through:

class Node0
    server.getHandler().getPackage();

It launches a NullPointerException.

Any idea how I can do that ?

  • 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-26T01:57:57+00:00Added an answer on May 26, 2026 at 1:57 am

    Why don’t you try to use a callback function? You can’t know when the Handler has set a package. You have to trigger the action from the handler.

    Based on your very minimalistic example, not tested or even compiling:

    class Node0
      private Server server;
      ...
      public void init(){
          server.setNode(this);
          server.waitConnections();
      ...
      public doPackage(Package p){
          // do something with p;
      ...
    
    class Server
      public setNode(Node n) {
          this.node = n;
      }
      socket = ss.accept(); // ss :socketServer object
      handler = new Handler(socket, node);
      handler.start(); // start handler thread
    
    class Handler
      ...
      public Handler(Socket socket, Node node){
        this.socket = socket;
        this.node = node;      
      }
      public void run() {
        while (true) {
          try {
            package = (Package) ois.readObject(); // ois :ObjectInputStream
            if (package != null) {
              // this.setPackage(package);
              this.node.doPackage(package);
            }
          } catch (Exception e) {
            break;
          }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML structure and want to convert it to an accordion. <div
I have this C++ code: extern C __declspec(dllexport) VOID AllocateFoo(MY_DATA_STRUCTURE** foo) { *foo =
I have up to 4 files based on this structure (note the prefixes are
I have a prefix trie. What is the recommended schema for representing this structure
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
I have a SVN structure like this: /Projects /Project1 /Project2 /someFolder /Project3 /Project4 I
Currently I have a structure like this: A | +--B | +--C It's mapped
I have already googled for this I have a Table with following structure in
I have a section of makefile that has this sort of structure: bob: ifdef
I have a XML Structure that looks like this. <sales> <item name=Games sku=MIC28306200 iCat=28

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.