这将是简短的,因为我不知道问题是什么。在我的onResponse of Volley Request中我正在创建一个TextView。这样做应用程序崩溃。我无法理解堆栈跟踪,因为它似乎是90%汇编(我的汇编知识由1和0组成)。这是一个堆栈的链接(它大约有50000个字符,我不知道它的相关内容......):https://justpaste.it/16l9m
这是onResponse:
int i = 0;
GridLayout.Spec r = GridLayout.spec(0, 1);
GridLayout.Spec c1 = GridLayout.spec(0, 1);
GridLayout.LayoutParams f1 = new GridLayout.LayoutParams(r, c1);
f1.rightMargin = 250;
GridLayout.Spec c2 = GridLayout.spec(1, 1);
GridLayout.LayoutParams l1 = new GridLayout.LayoutParams(r, c2);
l1.rightMargin = 25;
GridLayout.Spec c3 = GridLayout.spec(2, 1);
GridLayout.LayoutParams p1 = new GridLayout.LayoutParams(r, c3);
p1.rightMargin = 25;
GridLayout.Spec c4 = GridLayout.spec(3, 1);
GridLayout.LayoutParams co = new GridLayout.LayoutParams(r, c4);
co.rightMargin = 25;
GridLayout.Spec c5 = GridLayout.spec(4,1);
GridLayout.LayoutParams d1 = new GridLayout.LayoutParams(r, c5);
TextView firstT = new TextView(context);
firstT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
firstT.setText("Product");
grid.addView(firstT, f1);
TextView lastT = new TextView(context);
lastT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
lastT.setText("Quantity");
grid.addView(lastT, l1);
TextView purchasesT = new TextView(context);
purchasesT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
purchasesT.setText("Price");
grid.addView(purchasesT, p1);
TextView creditsT = new TextView(context);
creditsT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
creditsT.setText("Credits");
grid.addView(creditsT, co);
/*TextView dateT = new TextView(context);
creditsT.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
creditsT.setText("Date");
grid.addView(dateT, d1);
*/
grid.refreshDrawableState();
try {
while (response.has(String.valueOf(i))) {
GridLayout.Spec row = GridLayout.spec(i + 1, 1);
GridLayout.Spec col1 = GridLayout.spec(0, 1);
GridLayout.LayoutParams f = new GridLayout.LayoutParams(row, col1);
GridLayout.Spec col2 = GridLayout.spec(1, 1);
GridLayout.LayoutParams l = new GridLayout.LayoutParams(row, col2);
GridLayout.Spec col3 = GridLayout.spec(2, 1);
GridLayout.LayoutParams p = new GridLayout.LayoutParams(row, col3);
GridLayout.Spec col4 = GridLayout.spec(3, 1);
GridLayout.LayoutParams c = new GridLayout.LayoutParams(row, col4);
GridLayout.Spec col5 = GridLayout.spec(4, 1);
GridLayout.LayoutParams d = new GridLayout.LayoutParams(row, col5);
TextView first = new TextView(context);
first.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
first.setText(response.getJSONObject(String.valueOf(i)).getString("Product"));
grid.addView(first, f);
TextView last = new TextView(context);
last.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
last.setText(response.getJSONObject(String.valueOf(i)).getString("Quantity"));
grid.addView(last, l);
TextView purchases = new TextView(context);
purchases.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
purchases.setText(response.getJSONObject(String.valueOf(i)).get("Price").toString());
grid.addView(purchases, p);
TextView credits = new TextView(context);
credits.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
credits.setText(response.getJSONObject(String.valueOf(i)).get("Credits").toString());
grid.addView(credits, c);
/*TextView date = new TextView(context);
credits.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
credits.setText(response.getJSONObject(String.valueOf(i++)).get("Date").toString());
grid.addView(date, d);
*/
grid.refreshDrawableState();
}
pd.cancel();
} catch (JSONException e) {
e.printStackTrace();
}
}
它不会在同一个TextView中每次都给出错误,但它始终在我实例化第一个Text的行上。最后,请尽量不要畏惧可怕的变量名称......我需要解决这个问题。
答案 0 :(得分:0)
我错误地评论了包含i ++的代码部分...... while循环根本就没有退出。