私はこの問題を解決するために立ち往生して夢中になっていますが、私には運がありません。私は以前にこの質問をしたときにSOメンバーが私に与えたすべてのガイドラインを試しました:(回答してくれたすべての人に感謝します。私はそれを解決するためにたくさん検索しますが、最後の希望は成功しません。このJSONParsingを解決できますか?PHPからデータを投稿し、Android EditTextボックスにデータを取得したいのですが、コーディングしましたが、初日から存在し、まだ解決されていない問題があります。エミュレーターと電話で異なるLogCatエラーが発生しました。私はあなたに私のjavaコードとLogCatエラーを提起しました。どんなガイドも私にとって貴重です。
私のJavaコードは、エラーが発生した場所です。
// save button
btnSave = (Button) findViewById(R.id.btnSave);
// getting product details from intent
Intent i = getIntent();
// getting product id (pid) from intent
cid = i.getStringExtra(TAG_CID);
// save button click event
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// starting background task to update product
new SaveTaskDetails().execute();
}
});
}
@Override
protected void onStart() {
super.onStart();
// Getting complete product details in background thread
new GetTaskDetails().execute();
}
/**
* Background Async Task to Get complete product details
* */
class GetTaskDetails extends AsyncTask<String, String, JSONObject> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
tDialog = new ProgressDialog(My_Task.this);
tDialog.setTitle("Please Wait");
tDialog.setMessage("Retrieving Task Details.");
tDialog.setIndeterminate(false);
tDialog.setCancelable(true);
tDialog.show();
}
/**
* Getting task details in background thread
* @return
**/
protected JSONObject doInBackground(String... params1) {
JSONObject my_task = null;
// updating UI from Background Thread
// Check for success tag
int success;
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cid", cid));
// getting product details by making HTTP request
// Note that product details url will use GET request
JSONObject json = JSONParser.makeHttpRequest(
url_read_mytask, "GET", params);
// check your log for json response
// Log.d("Single Task Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray my_taskObj = json
.getJSONArray(TAG_MYTASK); // JSON Array
// get first product object from JSON Array
my_task = my_taskObj.getJSONObject(0);
}
else
{
// task with cid not found
}
}
catch (JSONException e) {
e.printStackTrace();
}
return my_task;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(JSONObject my_task) {
// dismiss the dialog once got all details
cus_name_txtbx = (EditText) findViewById(R.id.cus_name_txtbx);
try {
cus_name_txtbx.setText(my_task.getString(TAG_NAME));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
contact_no_txtbx = (EditText) findViewById(R.id.contact_no_txtbx);
try {
contact_no_txtbx.setText(my_task.getString(TAG_CONTACT));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ticket_no_txtbx = (EditText) findViewById(R.id.ticket_no_txtbx);
try {
ticket_no_txtbx.setText(my_task.getString(TAG_TICKET));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
task_detail_txtbx = (EditText) findViewById(R.id.task_detail_txtbx);
try {
task_detail_txtbx.setText(my_task.getString(TAG_TASKDETAIL));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tDialog.dismiss();
}
}
/**
* Background Async Task to Save product Details
* */
class SaveTaskDetails extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
tDialog = new ProgressDialog(My_Task.this);
tDialog.setTitle("Please Wait");
tDialog.setMessage("Saving Task");
tDialog.setIndeterminate(false);
tDialog.setCancelable(true);
tDialog.show();
}
/**
* Saving product
* */
protected String doInBackground(String... args) {
// getting updated data from EditTexts
String cus_name = cus_name_txtbx.getText().toString();
String contact_no = contact_no_txtbx.getText().toString();
String ticket_no = ticket_no_txtbx.getText().toString();
String task_detail = task_detail_txtbx.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(TAG_CID, cid));
params.add(new BasicNameValuePair(TAG_NAME, cus_name));
params.add(new BasicNameValuePair(TAG_CONTACT, contact_no));
params.add(new BasicNameValuePair(TAG_TICKET, ticket_no));
params.add(new BasicNameValuePair(TAG_TASKDETAIL, task_detail));
// sending modified data through http request
// Notice that update product url accepts POST method
JSONObject json = JSONParser.makeHttpRequest(url_update_mytask,
"POST", params);
// check json success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully updated
Intent i = getIntent();
// send result code 100 to notify about product update
setResult(100, i);
finish();
} else {
// failed to update product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once product uupdated
tDialog.dismiss();
}
}
私のLogcatエラーは次のとおりです。
01-01 11:28:52.549: E/WindowManager(31782): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 11:38:15.149: E/WindowManager(1133): Activity com.example.visit.record.My_Task has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054ce88 that was originally added here
01-01 11:38:15.149: E/WindowManager(1133): android.view.WindowLeaked: Activity com.example.visit.record.My_Task has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4054ce88 that was originally added here
01-01 11:38:15.149: E/WindowManager(1133): at android.view.ViewRoot.<init>(ViewRoot.java:277)
01-01 11:38:15.149: E/WindowManager(1133): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-01 11:38:15.149: E/WindowManager(1133): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-01 11:38:15.149: E/WindowManager(1133): at android.view.Window$LocalWindowManager.addView(Window.java:433)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.Dialog.show(Dialog.java:288)
01-01 11:38:15.149: E/WindowManager(1133): at com.example.visit.record.My_Task$GetTaskDetails.onPreExecute(My_Task.java:139)
01-01 11:38:15.149: E/WindowManager(1133): at android.os.AsyncTask.execute(AsyncTask.java:391)
01-01 11:38:15.149: E/WindowManager(1133): at com.example.visit.record.My_Task.onStart(My_Task.java:118)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1225)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.Activity.performStart(Activity.java:3941)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
01-01 11:38:15.149: E/WindowManager(1133): at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 11:38:15.149: E/WindowManager(1133): at android.os.Looper.loop(Looper.java:143)
01-01 11:38:15.149: E/WindowManager(1133): at android.app.ActivityThread.main(ActivityThread.java:4268)
01-01 11:38:15.149: E/WindowManager(1133): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 11:38:15.149: E/WindowManager(1133): at java.lang.reflect.Method.invoke(Method.java:507)
01-01 11:38:15.149: E/WindowManager(1133): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-01 11:38:15.149: E/WindowManager(1133): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-01 11:38:15.149: E/WindowManager(1133): at dalvik.system.NativeStart.main(Native Method)
親切にご案内します。新しいGetTaskDetails()。execute();でエラーが発生しました 。**tDialog.show();**
GetTaskDetailsクラスのPreExecuteについて