如何访问它们的try-catch里面的变量? [英] How to access variables which are inside try-catch?
本文介绍了如何访问它们的try-catch里面的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
林做这样的事情。
JSONArray json = uf.getAllRows();
(int x = 0; x <= json.length(); x++) {
JSONObject jo = json.getJSONObject(x); //Eclipse is suggesting that use try-catch here.
String name = jo.getString("username");
mainll[x] = new LinearLayout(this);
mainll[x].setId(x);
mainll[x].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mainll[x].setGravity(Gravity.CENTER);
.
.
.
.
}
如果我使用尝试捕捉比乔是不是在下面的行认可的:
if i use try catch than "jo" is not recognized at the following line:
String name = jo.getString("username");
谁能告诉我怎样才能解决这个问题?
Can anyone please tell me how can i solve this problem?
推荐答案
只是包装一切
try{
JSONArray json = uf.getAllRows();
(int x = 0; x <= json.length(); x++) {
JSONObject jo = json.getJSONObject(x); //Eclipse is suggesting that use try-catch here.
String name = jo.getString("username");
mainll[x] = new LinearLayout(this);
mainll[x].setId(x);
mainll[x].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mainll[x].setGravity(Gravity.CENTER);
}
catch(Exception e){}
这篇关于如何访问它们的try-catch里面的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文