我创建了一个Android应用程序,当我尝试在我的组和我的杂项组模块中查看成员时,日志cat中会显示以下错误。
07-15 08:25:26.647: W/System.err(851): org.json.JSONException: No value for all_group_emails
07-15 08:25:26.647: W/System.err(851): at org.json.JSONObject.get(JSONObject.java:355)
07-15 08:25:26.647: W/System.err(851): at org.json.JSONObject.getJSONArray(JSONObject.java:549)
07-15 08:25:26.647: W/System.err(851): at com.sunmobileappnow.mobileappnow.viewgroup$ViewMembers.doInBackground(viewgroup.java:88)
07-15 08:25:26.647: W/System.err(851): at com.sunmobileappnow.mobileappnow.viewgroup$ViewMembers.doInBackground(viewgroup.java:1)
07-15 08:25:26.647: W/System.err(851): at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-15 08:25:26.667: W/System.err(851): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-15 08:25:26.667: W/System.err(851): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
07-15 08:25:26.667: W/System.err(851): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-15 08:25:26.667: W/System.err(851): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-15 08:25:26.667: W/System.err(851): at java.lang.Thread.run(Thread.java:841)
有我的java代码。在这个java代码和php服务中,Group_details是as方法名称,all_group_emails是带有php servisces的数组,在json中,add_emails_my group是php admin数据库,其中存储了所有电子邮件ID。我从我这边以适当的方式宣布了一切,但我不知道我错在哪里。我无法在列表视图中获得价值。我发布了每个代码,请告诉我哪里错了。
public class viewgroup extends Activity {enter code here
ListView lv;
ArrayList<String> emailArray = new ArrayList<String>();
ArrayAdapter<String> adapter ;
private String login_token;
private SharedPreferences pref;
TextView t1;
protected Handler handler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewgroup);
lv= (ListView) findViewById(R.id.list);
t1=(TextView) findViewById(R.id.textView1);
t1.setText("My Group Members");
pref=getSharedPreferences("Driver", MODE_WORLD_READABLE);
login_token = pref.getString("login_token", "login_token");
handler.post( new Runnable() {
public void run() {
new ViewMembers().execute();
}
});
}
private class ViewMembers extends AsyncTask<String, String, String[]> {
ProgressDialog pDialog = new ProgressDialog(viewgroup.this);
@Override
protected String[] doInBackground(final String... params)
{
ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected())
{
HttpClient httpclient = new DefaultHttpClient();
try
{
JSONObject job= new JSONObject();
job.put("status_key","0");
job.put("method","group_details");
job.put("login_token",login_token);
StringEntity se = new StringEntity(job.toString());
HttpPost httppost = new HttpPost("http://suntechwebsolutions.com/clients/DGCapp/webservice.php");
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
String data = EntityUtils.toString(response.getEntity());
JSONObject jo = new JSONObject(data);
Log.d("response", jo.toString(4));
JSONArray jArray = jo.getJSONArray("all_group_emails");
for (int i=0; i < jArray.length(); i++)
{
System.out.println("please print my name...for....");
try {
JSONObject jsob = jArray.getJSONObject(i);
emailArray.add(jsob.getString("email_id").toString());
System.out.print("email array is: "+ emailArray);
adapter = new ArrayAdapter<String>(viewgroup.this, R.layout.listrow, emailArray);
} catch (JSONException e) {
}
}}
catch (Exception e)
{
e.printStackTrace();
}
}
else
{
final AlertDialog.Builder alert = new AlertDialog.Builder(viewgroup.this);
alert.setTitle("Alert !");
alert.setMessage("No Internet connection ");
alert.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton)
{
dialog.dismiss();
}
});
runOnUiThread(new Runnable()
{
public void run()
{
//pDialog.dismiss();
alert.show();
}
});
}
return params;
}
@SuppressLint("NewApi")
@Override
protected void onPostExecute(String[] result)
{
super.onPostExecute(result);
lv.setAdapter(adapter);
}
}
}
json response:
07-15 08:25:26.647: D/response(851): {
07-15 08:25:26.647: D/response(851): "message": "No Data has been Found.",
07-15 08:25:26.647: D/response(851): "err-code": "410"
07-15 08:25:26.647: D/response(851): }
web services
function group_details($data)
{
$user_id = NULL;
if ($user_id = getUser($data -> login_token))
{
$msg = array();
$sql = mysql_query("SELECT id,email FROM `add_emails_mygroup` WHERE user_id='$user_id'");
if (mysql_affected_rows() > 0)
{
while($get = mysql_fetch_assoc($sql))
{
$msg[] = $get;
}
return array("all_group_emails" => $msg, "err-code" => "0");
}
else
{
return array("message" => "No Data has been Found.", "err-code" => "410");
}
}
else
{
return array("err-code"=>"1","data"=>"Session Expired");
}
}