Пытаюсь через приложение создать запись в базу данных сайта. После того как я в приложении ввожу данные(имя, фамилия, пароль, емайл) и нажимаю кнопку, которая запускает этот процесс - приложение вылетает. LogCat:
09-12 18:56:56.981: ERROR/Buffer Error(2343): Error converting result java.lang.NullPointerException
09-12 18:56:57.058: ERROR/JSON Parser(2343): Error parsing data org.json.JSONException: End of input at character 0 of
09-12 18:56:57.358: WARN/dalvikvm(2343): threadid=9: thread exiting with uncaught exception (group=0x40015560)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): FATAL EXCEPTION: AsyncTask #1
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): java.lang.RuntimeException: An error occured while executing doInBackground()
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at android.os.AsyncTask$3.done(AsyncTask.java:200)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.lang.Thread.run(Thread.java:1019)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): Caused by: java.lang.NullPointerException
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at ru.mystory.text.Regictration$RegNewUser.doInBackground(Regictration.java:106)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at ru.mystory.text.Regictration$RegNewUser.doInBackground(Regictration.java:1)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-12 18:56:57.818: ERROR/AndroidRuntime(2343): ... 4 more
Код Activity:
public class Regictration extends Activity {
EditText nameReg, familReg, elMailReg, passWordReg;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static String url_registration = "http://site.ru/reg.php";
private static final String TAG_SUCCESS = "success";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.regictration);
nameReg = (EditText) findViewById(R.id.name);
familReg = (EditText) findViewById(R.id.famil);
elMailReg = (EditText) findViewById(R.id.elMail);
passWordReg = (EditText) findViewById(R.id.passWord);
Button btnRegOk = (Button) findViewById(R.id.buttonReg);
btnRegOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new RegNewUser().execute();
}
});
}
class RegNewUser extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Regictration.this);
pDialog.setMessage("Создание продукта...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
System.out.println("Начало регистрации");
}
protected String doInBackground(String[] args) {
String name = nameReg.getText().toString();
String famil = familReg.getText().toString();
String email = elMailReg.getText().toString();
String password = passWordReg.getText().toString();
// Заполняем параметры
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("famil", famil));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
// получаем JSON объект
JSONObject json = jsonParser.makeHttpRequest(url_registration, "POST", params);
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
System.out.println("Зарегистрирован");
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
System.out.println("Конец");
}
}
}
Код php обработчика:
<?php
$response = array();
if (isset($_POST['password']) && isset($_POST['name']) && isset($_POST['famil'])) {
require 'db_connect.php';
$db = new DB_CONNECT();
$name = mysql_real_escape_string($_POST['name']);
$password = md5(md5(trim($_POST['password'])));
$famil = mysql_real_escape_string($_POST['famil']);
$zapros = mysql_query("INSERT INTO users(name, password, famil) VALUES('$name', '$password', '$famil')");
if ($zapros) {
$response["success"] = 1;
$response["message"] = "Okay!";
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "Errors!";
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Error! Zapolneni ne vse polya";
echo json_encode($response);
}
?>
В браузере ответ получается такой:
{"success":0,"message":"Error! Zapolneni ne vse polya"}
Буду благодарен за помощь!