Android 使用insertOrThrow的ContentValues获取带引号的字符串

Android 使用insertOrThrow的ContentValues获取带引号的字符串,android,insert,sqlite,Android,Insert,Sqlite,如何在ContentValues对象中获取要在sqlite插入中使用的带引号的字符串?SQLite似乎被“我的价值”这个词扼杀了 //inside a for loop of a NodeList ContentValues map = new ContentValues(); Element elm; elm = (Element) nodes.item(i); String elmname = elm.getTagName(); map.put

如何在ContentValues对象中获取要在sqlite插入中使用的带引号的字符串?SQLite似乎被“我的价值”这个词扼杀了

    //inside a for loop of a NodeList
    ContentValues map = new ContentValues();
    Element elm;
    elm = (Element) nodes.item(i);
    String elmname = elm.getTagName();
    map.put("foto", getValue(elm, "foto"));
    map.put("fotonormal", getValue(elm, "foto-normal"));
    map.put("link", getValue(elm, "link"));

    myDatabase.beginTransaction();
    try {
        myDatabase.insertOrThrow(TABLE_ENDING, null, map);
        Log.i(TAG, "Added");
        myDatabase.setTransactionSuccessful();
    } catch (Exception err) {
        Log.i(TAG, "Transaction failed. Exception: " + err.getMessage());
    } finally {
        myDatabase.endTransaction();
    }
这给了我这个错误

Transaction failed. Exception: unrecognized token: ":": INSERT INTO tbl_ending (fotonormal, foto, link) VALUES (https://example.com/fotonormal.jpg, https://example.com/foto.jpg, https://example.com/);
我认为SQL语句应该是

INSERT INTO tbl_ending (fotonormal, foto, link) VALUES ("https://example.com/fotonormal.jpg", "https://example.com/foto.jpg",  "https://example.com/");

我怎样才能得到这个输出呢?

这确实是一个非常奇怪的行为。您的map.put语句中基本上存在弱输入,这没有帮助。我倾向于显式转换getValue参数,只是为了看看这是否解决了问题,即:

map.put("foto", (String) getValue(elm, "foto"));
map.put("fotonormal", (String) getValue(elm, "foto-normal"));
map.put("link", (String) getValue(elm, "link"));

Phillip的回答让我走上了正确的道路,我将函数getValue的返回值转换为字符串

return (String) getElementValue(n.item(0));

现在我可以成功插入。

现在我得到错误消息,事务失败。异常:错误代码19:约束失败。我认为这与太多的引用有关: