Android Sql 空指针异常
我在 Android SQL 查询方面遇到了一些问题。
这是我的代码:
Communicator rpc;
dbHelper = new DataBaseHelper(context, "oops_sys_tpl.sqlite", null, 1);
dbHelper.getDatabase();
dbHelper.executeQuery("users", "id", "75");
dbHelper.executeQuery("users", "objectId", "2");
dbHelper.executeQuery("users","serverName","ooops.com");
dbHelper.executeQuery("users", "username", "muphet");
newServerName = "stampii.com";
Log.w("UserId","Show user Id : "+userId);
int uuId = rpc.localUserIdByServerUserId(userId,newServerName);
Log.w("uuId","uuId : "+uuId);
在 Communicator 类中:
public static int localUserIdByServerUserId(int serverUserId){
String query = "SELECT id FROM users WHERE objectId = "+serverUserId+" LIMIT 1";
Map<String,Object> result = new HashMap<String,Object>();
result.get(dbHelper.executeSQLQuery(query));
int uuid = Integer.parseInt(result.get(0).toString());
return uuid;
}
public static int localUserIdByServerUserId(int serverUserId, String serverName){
String query = "SELECT id FROM users WHERE objectId = "+serverUserId+" AND serverName = "+serverName+" LIMIT 1";
Map<String,Object> result = new HashMap<String,Object>();
result.get(dbHelper.executeSQLQuery(query));
int uuid = Integer.parseInt(result.get(0).toString());
Log.w("localUSerByIdServerUserId","LocalUserByIdServerUserId result : "+uuid);
return uuid;
}
在 DatabaseHelper 类中:
SQLIteDatabase sqliteDb;
public boolean executeQuery(String tableName,String keys,String value){
return execQuery(tableName,keys,value);
}
private static boolean execQuery(String tableName,String key,String value){
sqliteDb = instance.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(key, value);
sqliteDb.insert(tableName, null, values);
return true;
}
它向我抛出一个 NullPointerException:
result.get(dbHelper.executeSQLQuery(query));
有什么建议我可以解决这个问题吗?
I have a little issue with Android SQL queries.
Here is the my code :
Communicator rpc;
dbHelper = new DataBaseHelper(context, "oops_sys_tpl.sqlite", null, 1);
dbHelper.getDatabase();
dbHelper.executeQuery("users", "id", "75");
dbHelper.executeQuery("users", "objectId", "2");
dbHelper.executeQuery("users","serverName","ooops.com");
dbHelper.executeQuery("users", "username", "muphet");
newServerName = "stampii.com";
Log.w("UserId","Show user Id : "+userId);
int uuId = rpc.localUserIdByServerUserId(userId,newServerName);
Log.w("uuId","uuId : "+uuId);
In Communicator class :
public static int localUserIdByServerUserId(int serverUserId){
String query = "SELECT id FROM users WHERE objectId = "+serverUserId+" LIMIT 1";
Map<String,Object> result = new HashMap<String,Object>();
result.get(dbHelper.executeSQLQuery(query));
int uuid = Integer.parseInt(result.get(0).toString());
return uuid;
}
public static int localUserIdByServerUserId(int serverUserId, String serverName){
String query = "SELECT id FROM users WHERE objectId = "+serverUserId+" AND serverName = "+serverName+" LIMIT 1";
Map<String,Object> result = new HashMap<String,Object>();
result.get(dbHelper.executeSQLQuery(query));
int uuid = Integer.parseInt(result.get(0).toString());
Log.w("localUSerByIdServerUserId","LocalUserByIdServerUserId result : "+uuid);
return uuid;
}
In DatabaseHelper class :
SQLIteDatabase sqliteDb;
public boolean executeQuery(String tableName,String keys,String value){
return execQuery(tableName,keys,value);
}
private static boolean execQuery(String tableName,String key,String value){
sqliteDb = instance.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(key, value);
sqliteDb.insert(tableName, null, values);
return true;
}
And it's throwin me a NullPointerException at :
result.get(dbHelper.executeSQLQuery(query));
Any suggestions how can I fix that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在此行中调用的方法:
result.get(dbHelper.executeSQLQuery(query));
和您在此处显示的方法public booleanexecuteQuery()
是不同的一个,所以我猜问题出在另一个。检查一下,您会找到答案,或将其粘贴到此处,以便我们为您提供帮助。The method that you are calling in this line :
result.get(dbHelper.executeSQLQuery(query));
and the method which you show herepublic boolean executeQuery()
are different one, so I guess the problem is in the other one.Check it and you will find the answer,or paste it here so we can help you.