0
我正在做一個名爲電話簿的Android應用程序。教師聯繫人保存在本地主機的數據庫中。只有在用戶提供有效密碼的情況下,聯繫人才能顯示。我已經編寫了登錄界面的程序。如果密碼正確,需要用戶輸入(密碼),則必須顯示「登錄成功」或「失敗」。 我的代碼中出現運行時錯誤。請幫助我。我試圖連接android和wamp登錄界面爲我的應用程序。我沒有得到輸出
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();
}
}
清單請!!! –