更改类型为字符串错误
问题描述:
我想向我的数据库添加一个整数,但它不会让我。更改类型为字符串错误
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>();
答
好吧, HashMap期待两个字符串。试试做HashMap<String, Integer> = new HashMap<String, Integer>();
我该如何改变它,所以它只接受int? – user3267882
@ User3267882:检查我更新的asnwer –