android 实现登陆界面时line.equals("true")总是false,怎么破
遇到的问题:情况通过php访问数据库,成功连接了,并且可以返回true 或 false,程序中的String line = reader.readLine();//读取数据。。。也读到true或false,但是if(line.equals("true"))得判断一直是false,line.equals("true")总是false,,这是为什么啊???求救
package com.demo.android.dummynote;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import com.google.hotmovie.MainActivity;
import com.google.hotmovie.ReYing;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class Second extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
findViews();
setListeners();
}
private Button button_ok;
private Button button_zhuce;
private Button button_quit;
private CheckBox checkbox;
private EditText editid;
private EditText editpwd;
private void findViews(){
button_ok=(Button)findViewById(R.id.button_ok);
button_zhuce=(Button)findViewById(R.id.button_zhuce);
button_quit=(Button)findViewById(R.id.button_quit);
editid=(EditText)findViewById(R.id.edittext_user2);
editpwd=(EditText)findViewById(R.id.edittext_password2);
}
private void setListeners(){
button_ok.setOnClickListener(ok);
button_zhuce.setOnClickListener(zhuce);
button_quit.setOnClickListener(quit);
}
private OnClickListener ok =new OnClickListener(){
public void onClick(View v){
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
String id=field_user.getEditableText().toString();//取用户名
String pwd=field_password.getEditableText().toString();//取用户名密码
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); //定义参数列表
nameValuePairs.add(new BasicNameValuePair("id",id)); //设置用户名参数
nameValuePairs.add(new BasicNameValuePair("pwd",pwd));//设置密码参数
InputStream is = null;
try{
HttpClient httpclient = new DefaultHttpClient(); //建立HTTP连接
HttpPost httppost = new HttpPost("http://zaiqiang.sinaapp.com/hotmovielogin.php/");//设定连接地址
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); //设定HTTP连接参数
HttpResponse response = httpclient.execute(httppost); //得到网页回应
HttpEntity entity = response.getEntity();//读取回应
is = entity.getContent(); //将回应装入输出流
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
String line = reader.readLine();//读取数据
if(line.equals("true")){//line.equals("true")==a成功进入,说明怎样都是false
Intent intent =new Intent();
intent.setClass(MainActivity.this,ReYing.class);
startActivity(intent);
}
else
Toast.makeText(MainActivity.this, "输入用户名或密码"+line, Toast.LENGTH_SHORT).show();
}catch(Exception e){ Log.e("log_tag", "Error in http connection "+e.toString()); }
}
};
private OnClickListener zhuce =new OnClickListener(){
public void onClick(View v){
}
};
private OnClickListener quit =new OnClickListener(){
public void onClick(View v){
Second.this.finish();
}
};
}
<?php
$conn = mysql_connect('w.rdc.sae.sina.com.cn:3307',SAE_MYSQL_USER,SAE_MYSQL_PASS) or die ("wrong!");
$sel=mysql_select_db("app_zaiqiang",$conn);
$sql="SELECT * FROM hotmovielogin WHERE id ='".$_REQUEST['id']."' and pwd ='".$_REQUEST['pwd']."'";
$que=mysql_query($sql,$conn);
$f="false";
$t="true";
if(mysql_fetch_object($que))
print($t);
else
print($f);
?>
android 界面 数据库 --------------------编程问答-------------------- String line = reader.readLine();//读取数据
第一输出line
不要调用toString();方法看结果,
第二,看看
equals()方法有没有被重写。
补充:Java , Eclipse