问题:删除评论部分时,我的应用程序崩溃了。但是在我尝试调试之后,问题似乎是在线价格文本视图[i] .setText(price [i])。任何人都可以帮助指出问题吗?谢谢
TextView[] quantityTextViews;
TextView[] priceTextViews;
int[] unitPrice = {5, 15, 40, 20, 25, 15, 20, 25, 10, 20};
int[] price = new int[10];
int[] quantity = new int[10];
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.balance_page);
textView();
Intent intent = getIntent();
String[] quantityOfItemString = intent.getStringArrayExtra (ShoppingPageActivity.EXTRA_MESSAGE);
for (int i = 0; i < quantityTextViews.length; i++) {
quantityTextViews[i].setText(quantityOfItemString[i]);
quantity[i] = Integer.parseInt(quantityOfItemString[i]);
price[i]= unitPrice[i]* quantity[i];
}
/*for (int i = 0; i < priceTextViews.length; i++) {
price[i]= unitPrice[i]* quantity[i];
priceTextViews[i].setText(price[i]);
}*/
}
public void textView() {
quantityTextViews = new TextView[]{
(TextView) findViewById(R.id.textView49),
(TextView) findViewById(R.id.textView48),
(TextView) findViewById(R.id.textView47),
(TextView) findViewById(R.id.textView46),
(TextView) findViewById(R.id.textView45),
(TextView) findViewById(R.id.textView44),
(TextView) findViewById(R.id.textView43),
(TextView) findViewById(R.id.textView42),
(TextView) findViewById(R.id.textView41),
(TextView) findViewById(R.id.textView40),
};
priceTextViews = new TextView[]{
(TextView) findViewById(R.id.textView51),
(TextView) findViewById(R.id.textView52),
(TextView) findViewById(R.id.textView53),
(TextView) findViewById(R.id.textView54),
(TextView) findViewById(R.id.textView55),
(TextView) findViewById(R.id.textView56),
(TextView) findViewById(R.id.textView57),
(TextView) findViewById(R.id.textView58),
(TextView) findViewById(R.id.textView59),
(TextView) findViewById(R.id.textView50),
};
}
答案 0 :(得分:2)
setText需要一个字符串。接受int的setText方法需要与应用程序中的文本资源相对应。
Bills::select( \DB::raw('DATE(`created_at`) as `date`'),\DB::raw('COUNT(*) as `count`'))->whereBetween('created_at', [Carbon\Carbon::parse('last sunday')->startOfDay(),Carbon\Carbon::parse('next monday')->endOfDay(), ]) ->groupBy('date')->get() ;
答案 1 :(得分:0)
当您使用带有int参数的setText时,它会自动使用setText(@StringRes int resid)
而不是void setText(CharSequence text)
,因此将您的参数转换为String或类似的CharSequence类型。
最简单的解决方案是
priceTextViews[i].setText("" + price[i]);