我现在编辑了…我检查布局和初始化但仍然是相同的错误..它可能是日食错误?
public class ActivityOwner extends Activity implements OnClickListener {
EditText ownerUser, ownerPass;
private Button btnLogin;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String OWNER_LOGIN_URL = "http://192.168.2.5/idot/owner_login.php";
// ---JSON element ids from response of php script
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_owner);
ownerUser = (EditText) findViewById(R.id.owner_login_username);
ownerPass = (EditText) findViewById(R.id.owner_login_password);
TextView tvLinkToRegister = (TextView) findViewById(R.id.link_to_register);
tvLinkToRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
Intent registrationForm = new Intent(ActivityOwner.this,
ActivityOwnerRegister.class);
startActivity(registrationForm);
}
});
btnLogin = (Button) findViewById(R.id.btnOwnerLogin);
btnLogin.setOnClickListener(this);
}
@Override
public void onClick(View v) {
new AttemptLogin().execute();
}
class AttemptLogin extends AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ActivityOwner.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// Check for success tag
int success;
String username = ownerUser.getText().toString();
String password = ownerPass.getText().toString();
try {
// Building Parameters
List params = new ArrayList();
params.add(new BasicNameValuePair("owner_username", username));
params.add(new BasicNameValuePair("owner_password", password));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(OWNER_LOGIN_URL,
"POST", params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Login Successful!", json.toString());
// save user data
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(ActivityOwner.this);
Editor edit = sp.edit();
edit.putString("owner_username", username);
edit.commit();
Intent i = new Intent(ActivityOwner.this,
ActivityOwnerSuccessLogin.class);
pDialog.dismiss();
finish();
startActivity(i);
return json.getString(TAG_MESSAGE);
} else {
Log.d("Login Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (result != null) {
Toast.makeText(ActivityOwner.this, result, Toast.LENGTH_SHORT)
.show();
}
}
}
}
—— logcat的——-
11-14 21:30:52.517: E/AndroidRuntime(18929): Caused by: java.lang.NullPointerException
11-14 21:30:52.517: E/AndroidRuntime(18929): at ph.idot.owner.ActivityOwner$AttemptLogin.doInBackground(ActivityOwner.java:88)
解决方法:
A.B.C形式的行上的空指针异常意味着点左侧的某些内容为空.在这个例子中:
> A无效;
>或A.B为空.
没有其他原因.因此,由于textView.getText()永远不会返回null,唯一的可能是用户为null.
标签:android,eclipse,android-asynctask,nullpointerexception
来源: https://codeday.me/bug/20191005/1856245.html