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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:45:56+00:00 2026-06-07T03:45:56+00:00

i am building a server to sends questions to clients and then receive answer

  • 0

i am building a server to sends questions to clients and then receive answer from them, but when i send a question to a client i want to make it as unaviable for sending again for one hour, i mean after i send a question to client , i want for one hour that question will never sends to any other clients,

static Hashtable<Integer, List<Integer>> unavialbeQuestions =
new Hashtable<Integer, List<Integer>>();

the key is the clientID, the value is list of the IDs of questions that will never send to that client in one hour, this function i used to make question as unaivalble

public void setUnavialbeQuestion(final String cellName, final int questionID) {
        List<Integer> cells = getCellsIntersectedWithCell(cellName);
        int cellID = getCellID(cellName);
        cells.add(cellID);
        for (int i = 0; i < cells.size(); i++) {
            if (unavialbeQuestions.containsKey(cellID)) {
                unavialbeQuestions.get(cells.get(i)).add(questionID);
            } else {
                List<Integer> lll = new LinkedList<Integer>();
                lll.add(questionID);
                unavialbeQuestions.put(cellID, lll);
            }
            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    f(cellName, questionID);
                }
            }, 1000 * 120);
        }
    }

see the function f() that will fired after one hour (in my demo just 2mins), here is the problem, i got null pointer exception when executing the f() function:

protected void f(String cellName, int questionDI) {
        // TODO Auto-generated method stub
        List<Integer> cells = getCellsIntersectedWithCell(cellName);
        int cellID = getCellID(cellName);
        cells.add(cellID);

        for(int i=0;i<cells.size();i++){
            int index = unavialbeQuestions.get(cells.get(i)).indexOf(questionDI);
            unavialbeQuestions.get(cells.get(i)).remove(index);
        }
    }

the exception on the index parameter,
what am i doing wrong?

  • 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-07T03:45:58+00:00Added an answer on June 7, 2026 at 3:45 am

    You don’t check that the returned list is not null here:

    unavialbeQuestions.get(cells.get(i)).indexOf(questionDI);
    

    and here:

    unavialbeQuestions.get(cells.get(i)).remove(index);
    

    And you use different keys for your map here:

    if (unavialbeQuestions.containsKey(cellID)) {
    

    and here:

    unavialbeQuestions.get(cells.get(i)).add(questionID);
    

    (and your code is not thread-safe, also)

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

Sidebar

Related Questions

i am building an application for clients to get questions from server and answer
I'm building a simple client-server chat system. The clients send data to the server
I am building an C++ application server-client where the client sends an image (170kb)
i am building a server application using eclipse , and the client is android
I am building an application where I have a server and a client that
I'm building an app (client) in C# which pings a server in my local
I'm building an erlang server. Users sends http requests to the server to update
I am building a real-time web-application with multiple clients and a node.js server to
I'm building a PhoneGap app where user press button which then sends data to
I'm currently building a multi-threaded server / client in Java with UDP via datagram

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.