こんにちは、私は今エラーがあります。なぜこのエラーが発生するのかわかりません。問題を指摘してもらえますか? ありがとう。これはエラーです:
**
01-29 20:14:46.738: E/AndroidRuntime(1827): FATAL EXCEPTION: main
01-29 20:14:46.738: E/AndroidRuntime(1827): java.lang.NullPointerException
01-29 20:14:46.738: E/AndroidRuntime(1827): at com.example.projectthesis.Register.validation(Register.java:55)
01-29 20:14:46.738: E/AndroidRuntime(1827): at com.example.projectthesis.Register$1.onClick(Register.java:49)
01-29 20:14:46.738: E/AndroidRuntime(1827): at android.view.View.performClick(View.java:4084)
01-29 20:14:46.738: E/AndroidRuntime(1827): at android.view.View$PerformClick.run(View.java:16966)
01-29 20:14:46.738: E/AndroidRuntime(1827): at android.os.Handler.handleCallback(Handler.java:615)
01-29 20:14:46.738: E/AndroidRuntime(1827): at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 20:14:46.738: E/AndroidRuntime(1827): at android.os.Looper.loop(Looper.java:137)
01-29 20:14:46.738: E/AndroidRuntime(1827): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-29 20:14:46.738: E/AndroidRuntime(1827): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 20:14:46.738: E/AndroidRuntime(1827): at java.lang.reflect.Method.invoke(Method.java:511)
01-29 20:14:46.738: E/AndroidRuntime(1827): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-29 20:14:46.738: E/AndroidRuntime(1827): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-29 20:14:46.738: E/AndroidRuntime(1827): at dalvik.system.NativeStart.main(Native Method)
**
これは私のコードです:
**
public class Register extends Activity {
EditText inputFname;
EditText inputLname;
EditText inputEmail;
EditText inputPassword;
EditText inputCpassword;
EditText inputCellno;
Button btnRegister;
private ProgressDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
inputFname = (EditText) findViewById(R.id.inputFname);
inputLname = (EditText) findViewById(R.id.inputLname);
inputEmail = (EditText) findViewById(R.id.inputEmail);
inputPassword = (EditText) findViewById(R.id.inputPassword);
inputCpassword = (EditText) findViewById(R.id.inputCpassword);
inputCellno = (EditText) findViewById(R.id.inputCellno);
Button btnRegister = (Button) findViewById(R.id.btnRegister);
// button click event
btnRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
validation();
}
});
}
public void validation() {
if (inputFname.getText().toString().equals("") || inputLname.getText().toString().equals("") || inputEmail.getText().toString().equals("")
|| inputPassword.getText().toString().equals("") || inputCpassword.getText().toString().equals("") || inputCellno.getText().toString().equals("")) {
Toast.makeText(getApplicationContext(), "Fill Empty Fields",
Toast.LENGTH_SHORT).show();
} else {
new phpconnect().execute();
}
}
class phpconnect extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Register.this);
pDialog.setMessage("Please Wait ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("fname", inputFname
.getText().toString()));
postParameters.add(new BasicNameValuePair("lname", inputLname
.getText().toString()));
postParameters.add(new BasicNameValuePair("eadd", inputEmail
.getText().toString()));
postParameters.add(new BasicNameValuePair("password", inputPassword
.getText().toString()));
postParameters.add(new BasicNameValuePair("cpassword", inputCpassword
.getText().toString()));
postParameters.add(new BasicNameValuePair("cellno", inputCellno
.getText().toString()));
// Passing Parameter to the php web service for authentication
// String valid = "1";
String response = null;
try {
response = CustomHttpClient
.executeHttpPost(
"http://10.0.2.2/TheCalling/index.php",
postParameters); // Enter Your remote PHP,ASP,
// Servlet
// file link
// error.setText(res);
} catch (Exception e) {
return "0";
}
return response;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String result) {
// dismiss the dialog once done
pDialog.dismiss();
String res = result.toString();
String num = "1";
res = res.trim();
res = res.replaceAll("\\s+", "");
if (res.equals(num)) {
// Display Toast
Toast.makeText(getApplicationContext(),
"Correct Username or Password", Toast.LENGTH_SHORT)
.show();
Intent i = new Intent(Register.this, MainMenu.class);
startActivity(i);
} else {
Toast.makeText(getApplicationContext(),
"Sorry!! Incorrect Username or Password",
Toast.LENGTH_SHORT).show();
}
}
}
}
**
このエラーは、ボタンをクリックした後に発生します。php コードが必要な場合は、次のとおりです。
**
<?php
include("db_config.php");
$fname=($_POST['fname']);
$mname=($_POST['mname']);
$lname=($_POST['lname']);
$eadd=($_POST['eadd']);
$password=($_POST['password']);
$cpassword=($_POST['cpassword']);
$cellno=($_POST['cellno']);
$sql="INSERT INTO `users` SET `fname`='{$_POST['fname']}', `lname`='{$_POST['lname']}', `eadd`='{$_POST['eadd']}', `password`='{$_POST['password']}', `cpassword`='{$_POST['cpassword']}', `cellno`='{$_POST['cellno']}'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$count=mysql_num_rows($result);
if($count==1)
{
echo "1";
//(If result found send 1 to android)
}
else
{
echo "0";
//(If result not found send o to android)
}
?>
**