Android Sql 空指针异常

发布于 2024-12-05 10:02:04 字数 2178 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉梦枕江山 2024-12-12 10:02:04

您在此行中调用的方法: 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 here public 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文