我有一个具有以下变量的活动
static CharSequence[] categories;
我正在使用 JSON 接收数据
try
{
Thread cThread = new Thread(new getStringContent("http://192.168.0.101/curltest/getcategories.php"));
cThread.start();
}
catch(Exception ex)
{
Log.i("YGo", ex.toString());
}
public class getStringContent implements Runnable {
String suri;
public getStringContent(String uri)
{
suri = uri;
}
@Override
public void run() {
try {
JSONArray jsonArray = new JSONArray(getPageContent(suri));
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray jsonSArray = jsonArray.getJSONArray(i);
categories = new CharSequence[jsonArray.length()];
categories[i] = jsonSArray.getString(0);
Log.i("YGo", categories[i].toString());
}
} catch (JSONException e) {
// TODO Auto-generated catch block
Log.e("YGo", e.toString());
}
dialog.dismiss();
}
}
在 GUI 线程中,如果我单击按钮,我想显示接收到的数据:
for(int i=0; i<categories.length; i++)
{
Log.i("Ygo", String.valueOf(categories[i]));
Log.i("Ygo", String.valueOf(selectedData[i]));
}
AlertDialog.Builder builder = new AlertDialog.Builder(PreferencesClass.this);
builder.setTitle("Pick categories");
builder.setMultiChoiceItems(categories, selectedData, onClickCatChooser);
builder.setPositiveButton("Ok", clickedOnClickCatOk);
AlertDialog alert = builder.create();
alert.show();
但在categories
我有的变量中null,null,Data3
,而不是Data1
我Data2
只有null
。为什么?