Problème NullPointerException
Salut , j'essaye d'ajouter des données dans ma base de données a travers android mais j'ai un problème lors de l’envoi voila le code j'ai utiliser et le logcat
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carte);
nomt = (EditText) findViewById(R.id.editText8);
prénomt = (EditText) findViewById(R.id.editText10);
comptet = (EditText) findViewById(R.id.editText11);
idt= (EditText)findViewById(R.id.editText12);
// Create button
Button btnCreateProduct = (Button) findViewById(R.id.button6);
// button click event
btnCreateProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// creating new product in background thread
new CreateNewProduct().execute();
}
});
}
/**
* Background Async Task to Create new product
* */
class CreateNewProduct extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Cartes.this);
pDialog.setMessage("Creating Product..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Creating product
* */
protected String doInBackground(String... args) {
String nom = nomt.getText().toString();
String prenom = prénomt.getText().toString();
String compte = comptet.getText().toString();
String id = idt.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("nom", nom));
params.add(new BasicNameValuePair("prenom", prenom));
params.add(new BasicNameValuePair("compte", compte));
params.add(new BasicNameValuePair("id", id));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
}
}
} |
le log cat
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
04-30 18:39:59.654 6155-6719/attijari.com.attijarimobileapp E/JSON Parser﹕ Error parsing data org.json.JSONException: Value OK of type java.lang.String cannot be converted to JSONObject
04-30 18:39:59.694 6155-6719/attijari.com.attijarimobileapp E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at attijari.com.attijarimobileapp.Cartes$CreateNewProduct.doInBackground(Cartes.java:160)
at attijari.com.attijarimobileapp.Cartes$CreateNewProduct.doInBackground(Cartes.java:121)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
************at java.util.concurrent.FutureTask.run(FutureTask.java:137)
************at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
************at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
************at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
************at java.lang.Thread.run(Thread.java:856)
04-30 18:40:07.892 6155-6155/attijari.com.attijarimobileapp E/WindowManager﹕ Activity attijari.com.attijarimobileapp.Cartes has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@419fd918 that was originally added here
android.view.WindowLeaked: Activity attijari.com.attijarimobileapp.Cartes has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@419fd918 that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:415)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:322)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:234)
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:153)
at android.view.Window$LocalWindowManager.addView(Window.java:559)
at android.app.Dialog.show(Dialog.java:301)
at attijari.com.attijarimobileapp.Cartes$CreateNewProduct.onPreExecute(Cartes.java:133)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
at android.os.AsyncTask.execute(AsyncTask.java:534)
at attijari.com.attijarimobileapp.Cartes$1.onClick(Cartes.java:113)
at android.view.View.performClick(View.java:4262)
at android.view.View$PerformClick.run(View.java:17421)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4944)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method) |