電話帳というAndroidアプリをやっています。教員の連絡先は、ローカル ホストのデータベースに保存されます。ユーザーが有効なパスワードを入力した場合にのみ、連絡先を表示する必要があります。ログインインターフェイス用のプログラムを作成しました。パスワードが正しい場合はユーザーから入力(パスワード)を取得し、「ログイン成功」を表示する必要があります。コードで実行時エラーが発生しています。私を助けてください。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
etUsn=(EditText)findViewById(R.id.edit);
login=(Button)findViewById(R.id.button1);
login.setOnClickListener(this);
}
public void onClick(View v)
{
httpclient = new DefaultHttpClient();
httppost= new HttpPost("http://10.0.2.2/log.php");
Usn=etUsn.getText().toString();
try
{
namevaluepair = new ArrayList<NameValuePair>(1);
namevaluepair.add(new BasicNameValuePair("Usn",Usn));
httppost.setEntity(new UrlEncodedFormEntity(namevaluepair));
response=httpclient.execute(httppost);
Toast.makeText(getBaseContext(), "hello", Toast.LENGTH_SHORT).show();
if(response.getStatusLine().getStatusCode()==200)
{
entity=response.getEntity();
if(entity!=null)
{
InputStream instream=entity.getContent();
JSONObject jsonResponse=new JSONObject(convertStreamToString(instream));
String retUsn;
retUsn =jsonResponse.getString("usn");//table field
if(Usn.equals(retUsn))
{
SharedPreferences sp=getSharedPreferences("login details", 0);
SharedPreferences.Editor spedit= sp.edit();
spedit.commit();
Toast.makeText(getBaseContext(), "Success", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Invalid usn", Toast.LENGTH_SHORT).show();
}
}
}
}catch (Exception e)
{
e.printStackTrace();
Toast.makeText(getBaseContext(), "connection error", Toast.LENGTH_SHORT).show();
}
}