ローカルホストで実行されているjspファイルにデータを送信しようとしています。電話で[送信]をクリックすると、アプリケーションが失敗し、表示されます。残念ながら、アプリケーションは停止しました。
LoginTask:
public class LoginTask extends AsyncTask<String, Void, Integer> {
private ProgressDialog progressDialog;
private LoginActivity activity;
private int id = -1;
public LoginTask(LoginActivity activity, ProgressDialog progressDialog)
{
this.activity = activity;
this.progressDialog = progressDialog;
}
@Override
protected void onPreExecute()
{
progressDialog.show();
}
@Override
protected Integer doInBackground(String... arg0)
{
String result = "";
int responseCode = 0;
try
{
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.100:8080/test/AndroidCheck.jsp");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", arg0[0]));
nameValuePairs.add(new BasicNameValuePair("password", arg0[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
int executeCount = 0;
HttpResponse response;
do
{
progressDialog.setMessage("Logging in.. ("+(executeCount+1)+"/5)");
executeCount++;
response = client.execute(httppost);
responseCode = response.getStatusLine().getStatusCode();
} while (executeCount < 5 && responseCode == 408);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null)
{
result = line.trim();
}
id = Integer.parseInt(result);
}
catch (Exception e) {
responseCode = 408;
e.printStackTrace();
}
return responseCode;
}
@Override
protected void onPostExecute(Integer headerCode)
{
progressDialog.dismiss();
if(headerCode == 202)
activity.login(id);
else
activity.showLoginError("");
}
}
LoginActivity:
public class LoginActivity extends Activity {
protected static final int LOGIN_REQUEST_CODE = 0;
protected static final int RECOVER_REQUEST_CODE = 1;
protected static final int REGISTER_REQUEST_CODE = 2;
public static final int LOGOUT_RESULT_CODE = 2;
SharedPreferences sharedPreferences;
private EditText username;
private EditText password;
private Button btnLogin;;
private final Class<?> LOGIN_DESTINATION = AndroidNavigationTabsActivity.class;
@Override
protected void onCreate(Bundle savedInstanceState)
{
sharedPreferences = getPreferences(MODE_PRIVATE);
super.onCreate(savedInstanceState);
if( sharedPreferences.getBoolean("user_logged_in", false))
{
startActivityForResult(
new Intent(LoginActivity.this, LOGIN_DESTINATION),
LOGIN_REQUEST_CODE);
}
setContentView(R.layout.login_activity);
username=(EditText)this.findViewById(R.id.username);
password=(EditText)this.findViewById(R.id.password);
btnLogin=(Button)this.findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(loginOnClickListener);
}
protected OnClickListener loginOnClickListener = new OnClickListener()
{
public void onClick(View v)
{
ProgressDialog progressDialog = new ProgressDialog(LoginActivity.this);
progressDialog.setMessage("Logging in...");
progressDialog.setCancelable(false);
LoginTask loginTask = new LoginTask(LoginActivity.this, progressDialog);
loginTask.execute(username.getText().toString(),password.getText().toString());
}
};
public void showLoginError(String result)
{
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setMessage(R.string.login_invalid_error);
AlertDialog alert = builder.create();
alert.setCancelable(false);
alert.show();
}
public void login(int id)
{
sharedPreferences.edit().putBoolean("user_logged_in", true).commit();
startActivityForResult(
new Intent(LoginActivity.this, LOGIN_DESTINATION),
LOGIN_REQUEST_CODE);
}
}
電話で[送信]をクリックすると、エラー(トースト)が表示されます。jspページ(AndroidCheck.jsp)に表示null
されます(Webページに表示しようとしています。電話に入力した内容:ユーザー名とログイン)。どこに問題があるのかわかりません...