java.lang.NumberFormatException: null -
i'm facing error:
`unable load properties file multiwordnet exception in thread "main" java.lang.numberformatexception: null @ java.lang.integer.parseint(integer.java:417) @ java.lang.integer.<init>(integer.java:660) @ org.itc.mwn.mysqldictionary.<init>(mysqldictionary.java:85)`
this property file mysqldictionary.java trying read:
#------------------------------------------------------------ #properties file properties multiwordnet api #hostname of mysql server mwn_hostname=localhost #user mwn_user=root #password mwn_passwd= #database name mwn_db=wordnet #cache of entity cache_capacity=1000
and,finally, part code fails:
public mysqldictionary() { try { connectionparameters = new properties(); connectionparameters.load(new fileinputstream(new file("./conf/multiwordnet.properties"))); } catch (java.io.ioexception ioee) { system.err.println("unable load properties file multiwordnet"); } /// connection drivers instance try { class.forname("com.mysql.jdbc.driver").newinstance(); //class.forname("org.gjt.mm.mysql.driver").newinstance(); } catch(classnotfoundexception e){ system.err.println("unable load driver"); } catch(illegalaccessexception e){ system.err.println("unable load driver"); } catch(instantiationexception e){ system.err.println("unable load driver"); } // multiwordnet db connection string host = connectionparameters.getproperty("mwn_hostname"); string user = connectionparameters.getproperty("mwn_user"); string passwd = connectionparameters.getproperty("mwn_passwd"); string dbname = connectionparameters.getproperty("mwn_db"); integer cache = new integer(connectionparameters.getproperty("cache_capacity")); //here parsing fails, file written! try { default_cache_capacity = cache.intvalue(); string conn = "jdbc:mysql://" + host + "/" + dbname; this.db = drivermanager.getconnection(conn,user,passwd); this.stmt = db.createstatement(); system.err.println("welcome multiwordnet api\nconnection database ...ok\n"); } catch (sqlexception e) { system.out.println("unable establish multiwordnet mysql db connection on " + host + "(" + user + " - " + passwd + ")"); e.printstacktrace(system.out); }
the strange thing program started failing, after running correctly
when dealing file
in java don't struggle relative paths. quite unpredictable since depend on current working directory on don't have total control. use classpath instead, loading resource using class loader:
properties properties = new properties(); properties.load(getclass().getresourceasstream("multiwordnet.properties"));
your problem isn't not being able parse integer, not being able load file.
Comments
Post a Comment