我有一个方法用于在 AppTools.java 中连接 HttpGet:
public class AppTools extends Activity {
public void connectToServerWithURL(String URL)
throws ClientProtocolException, IOException, JSONException {
/* Start connect */
new Thread() {
client = new DefaultHttpClient();
request = new HttpGet(URL);
response = client.execute(request);
reader = new BufferedReader(new InputStreamReader(response.getEntity()
.getContent()));
builder = new StringBuilder();
for (String s = reader.readLine(); s != null; s = reader.readLine()) {
builder.append(s);
}
if (builder != null) {
/* Transfer to JSONArray */
jsonTransfer = new JSONObject(builder.toString());
systemConfigJSONArray = jsonTransfer.getJSONArray(config);
runOnUiThread(performResult);
}
}.start();
}
private Runnable performResult = new Runnable() {
public void run() {
closeProgressDialog();
performResult(systemConfigJSONArray);
}
};
/** Connect complete, interface for Override **/
public void performResult(JSONArray resultArray) {
}
而且,在另一个 Activity 中扩展了 AppTools:
public class A extends AppTools {
在活动 A 中有一个 AlertDialog 用于选择要连接的 url:
new AlertDialog.Builder(this).setView(aLayout)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
/* Set command */
if (spinner_options.getSelectedItemPosition() == 0) {
connectToServerWithURL("http://...");
} else if (spinner_options
.getSelectedItemPosition() == 1) {
connectToServerWithURL("http://...");
}
}
}).setNegativeButton("Cancel", null).show();
里面的aLayout.setView(aLayout)
有一个Spinner,所以setPositiveButton的onClick接口
将获得微调器的选定位置并执行该方法
但代码无法运行,LogCat 显示 AlertController$ButtonHandler 错误
问题是什么?