Note that there are some explanatory texts on larger screens.

plurals
  1. POJava exception when adding to map
    primarykey
    data
    text
    <p>Not sure what is wrong...it should work or maybe am missing something? the following is the code:</p> <pre><code>public class TestOracleMap implements java.io.Serializable{ static TreeMap&lt;String, Integer&gt; map; static TreeMap&lt;String, Integer&gt; localMap = new TreeMap&lt;String, Integer&gt;(); public static void StoreMapInDB(TreeMap&lt;String, Integer&gt; 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); } } } </code></pre> <p>the error is in the line in the main method that is:</p> <pre><code>map.put("Hello!", x); </code></pre> <p>it gives:</p> <pre><code>Exception in thread "main" java.lang.NullPointerException at core.smd.classes.TestOracleMap.main(TestOracleMap.java:61) Java Result: 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload