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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:35:49+00:00 2026-05-27T08:35:49+00:00

Not sure what is wrong…it should work or maybe am missing something? the following

  • 0

Not sure what is wrong…it should work or maybe am missing something? the following is the code:

public class TestOracleMap implements java.io.Serializable{
static TreeMap<String, Integer> map;
static TreeMap<String, Integer> localMap = new TreeMap<String, Integer>();

public static void StoreMapInDB(TreeMap<String, Integer> map) throws
        IOException, FileNotFoundException{
    try {
  PreparedStatement insertMap = null;
  //String insertString = "INSERT INTO TESTMAP(ID, MPFIELD) VALUES (1, ?)";
  Connection con=null;
  con.setAutoCommit(false);
  Class.forName("oracle.jdbc.driver.OracleDriver");
  con=DriverManager.getConnection(
    "jdbc:oracle:thin:@oXXX",
    "XXX",
    "XXX");

  ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
  ObjectOutputStream out = new ObjectOutputStream(bos);
  out = new ObjectOutputStream(bos) ;
  out.writeObject(map);
  out.close();

  byte[] buf = bos.toByteArray();
  PreparedStatement prepareStatement = con.prepareStatement("insert into  

  TESTMAP(ID,MAPFIELD)values(?,?)");
  prepareStatement.setLong(1, 1);
  prepareStatement.setBinaryStream(2, new ByteArrayInputStream(buf), buf.length);



 // insertMap.executeUpdate();
  con.commit();
    } catch(Exception e){e.printStackTrace();}
}

public static void main(String[] args)
{
    try{
    DateTime today = new DateTime();
    int x = 1;
    map.put("Hello!", x);
    StoreMapInDB(map);
    }catch(IOException ioe){
        System.err.print(ioe);
    }
}
}

the error is in the line in the main method that is:

map.put("Hello!", x);

it gives:

Exception in thread "main" java.lang.NullPointerException
at core.smd.classes.TestOracleMap.main(TestOracleMap.java:61)
 Java Result: 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-27T08:35:50+00:00Added an answer on May 27, 2026 at 8:35 am

    Seems like you never instantiate map. You declare it here

    static TreeMap<String, Integer> map;
    

    but when you use it here it is still null giving you the NullPointerException.

    map.put("Hello!", x);
    

    If you do this before

    map = new TreeMap<String, Integer>();
    

    it should run fine.

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

Sidebar

Related Questions

Not sure what is wrong with this code. I keep getting the following error:
I'm not sure what's wrong with the following setup. I have a View that
not sure what is wrong with this jquery code: http://jsfiddle.net/aCABM/ I want to to
I am not sure what's wrong with this code : std::vector<int> myVector(0); if (myVector.back()
I'm not sure whts wrong with this code... else if (combo_View.Text == Orders) {
I am not sure what is wrong with the following syntax. I would like
Below is my very simple static class. Not sure what is wrong. I am
I am not sure whats wrong with my code. delimiter $$ CREATE TRIGGER updateRestaurantAtributes
I got this error message and I'm not quite sure whats wrong: Exception in
Not sure what I'm doing wrong with .live() $(function(){ var wrapper = $('#trailer_wrapper'); var

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.