我在创建与Firebird数据库的android连接时遇到问题,每当执行连接线时应用程序都会崩溃。
代码:
cod = ""+edit[0].getText();
cod = String.format("%14s", cod).replace(' ', '0');
String query = "SELECT DS_PRO FROM PROD WHERE CD_PRO = '"+cod+"'";
try{
Class.forName("org.firebirdsql.jdbc.FBDriver").newInstance();
System.err.println("jdbc created");
}catch(Exception e){
System.err.println("Cannot create connection");
}
try{
Properties props = new Properties();
props.setProperty("user", "POINTER");
props.setProperty("password", "pwdb");
props.setProperty("encoding", "WIN1252");
try{
System.err.println("creating connection");
java.sql.Connection connection = DriverManager.getConnection("jdbc:firebirdsql:192.168.0.196/3050:C:/Fenix/FENIX.FDB",props);
System.err.println("created connection");
}
catch(Exception e){
System.err.println("error in connection to server");
System.err.println(e.getMessage());
}
}
catch(Exception e){
System.err.println("error in connection to server");
System.err.println(e.getMessage());
}
这是eclipse的logcat中的消息:
01-29 09:22:44.774: W/System.err(28820): jdbc created
01-29 09:22:44.774: W/System.err(28820): creating connection
01-29 09:22:44.974: E/AndroidRuntime(28820): FATAL EXCEPTION: AsyncTask #3
01-29 09:22:44.974: E/AndroidRuntime(28820): Process: com.example.testeconnection, PID: 28820
01-29 09:22:44.974: E/AndroidRuntime(28820): java.lang.RuntimeException: An error occured while executing doInBackground()
01-29 09:22:44.974: E/AndroidRuntime(28820): at android.os.AsyncTask$3.done(AsyncTask.java:300)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
01-29 09:22:44.974: E/AndroidRuntime(28820): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.lang.Thread.run(Thread.java:811)
01-29 09:22:44.974: E/AndroidRuntime(28820): Caused by: java.lang.ExceptionInInitializerError
01-29 09:22:44.974: E/AndroidRuntime(28820): at org.firebirdsql.jdbc.FBDriverPropertyManager.<clinit>(FBDriverPropertyManager.java:142)
01-29 09:22:44.974: E/AndroidRuntime(28820): at org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:103)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.sql.DriverManager.getConnection(DriverManager.java:179)
01-29 09:22:44.974: E/AndroidRuntime(28820): at com.example.testeconnection.BdConnect.doInBackground(BdConnect.java:55)
01-29 09:22:44.974: E/AndroidRuntime(28820): at com.example.testeconnection.BdConnect.doInBackground(BdConnect.java:1)
01-29 09:22:44.974: E/AndroidRuntime(28820): at android.os.AsyncTask$2.call(AsyncTask.java:288)
01-29 09:22:44.974: E/AndroidRuntime(28820): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-29 09:22:44.974: E/AndroidRuntime(28820): ... 4 more
01-29 09:22:44.974: E/AndroidRuntime(28820): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Set java.util.Properties.entrySet()' on a null object reference
01-29 09:22:44.974: E/AndroidRuntime(28820): at org.firebirdsql.jdbc.FBConnectionHelper.loadDpbParameterTypes(FBConnectionHelper.java:289)
01-29 09:22:44.974: E/AndroidRuntime(28820): at org.firebirdsql.jdbc.FBConnectionHelper.<clinit>(FBConnectionHelper.java:106)
01-29 09:22:44.974: E/AndroidRuntime(28820): ... 11 more
有人有这个错误的任何信息吗?
答案 0 :(得分:0)
问题在于资产文件夹中的属性文件,如Mark所建议的那样。在初始化程序中
props = loadProperties("assets/isc_dpb_types.properties");
返回null,这会导致NullReferenceException下面的一些行。
在Android Studio 2.2版中,解决方案是添加
assets.srcDirs = ['assets']
这里:
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
....
}
buildTypes {
release {
...
}
}
sourceSets {
main {
assets.srcDirs = ['assets']
}
}
}
项目graddle文件中的