更改类型为字符串错误

问题描述:

我想向我的数据库添加一个整数,但它不会让我。更改类型为字符串错误

int count =0; 
    public void editHighScores(){ 

    HashMap<String, String> queryValues = new HashMap<String, String>(); 
    queryValues.put("totalWins", count); 

    myDatabase.insertHighScores(queryValues); 
} 

你必须定义地图接受String键和String值,所以你can'y把一个int为值。

如果你不能确定的价值类型,然后保持它作为Object

HashMap<String, Object> queryValues = new HashMap<String, Object>(); 

或者,如果你知道值将是永远只有INT,然后定义像

HashMap<String, Integer> queryValues = new HashMap<String, Integer>(); 
+0

我该如何改变它,所以它只接受int? – user3267882

+0

@ User3267882:检查我更新的asnwer –

好吧, HashMap期待两个字符串。试试做HashMap<String, Integer> = new HashMap<String, Integer>();

+0

'int'作为泛型?不可能 –

+0

它必须是'HashMap '。 –

+0

哦正确的整数 – safaiyeh