1
基本上我有一个TableLayout与几个TableRows,每个包含5个单元格(Name,Price,Count,IncreaseButton,DecreaseButton),然后我写了一个函数来返回一个某些行,但我不断收到异常。读取TableRow单元格值并返回一个整数
这是代码:
private int getRowPrice(View target) //target is a Button
{
TableRow row = (TableRow) target.getParent();
TextView priceCell = (TextView) row.getChildAt(1);
String price = priceCell.getText().toString();
//The cell text may start with $ or another currency
if (price.startsWith(getString(R.string.currency)))
{
price = price.substring(getString(R.string.currency).length()).toString();
}
return Integer.getInteger(price); //Here I get a "java.lang.NullPointerException"
}
如果我Log.d()它输出正确的值,如果我尝试返回正常工作getInteger(“10”),也调试器价格将'价格'分类为一个字符串。所以我必须承认,我不知道为什么这个错误会持续发生。
并请让我知道,如果有更好的,错误倾向更低的方式来获得一定行的单元格)