何が間違っているか分かりません...うまくいくはずですか、何か不足していますか?マップに追加するときのJava例外
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);
}
}
}
誤りがあるmainメソッドに沿ったものである:
map.put("Hello!", x);
ことができます:
Exception in thread "main" java.lang.NullPointerException
at core.smd.classes.TestOracleMap.main(TestOracleMap.java:61)
Java Result: 1
「地図」を初期化しましたか?私にはヌルに見えます。 – duffymo
どこかで「地図」を初期化しましたか?私はlocalMapの初期化だけを参照してください... – Volker