我正在使用一个简单的应用程序遇到一些麻烦。
我将包含代码:
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import java.net.URL;
public class login extends AppCompatActivity {
EditText user;
EditText pass;
boolean result_back;
private ProgressDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button log = (Button) findViewById(R.id.btLogIn2);
log.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
login(v);
}
});
}
public void login(View v)
{
HttpClient client = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpResponse response = null;
user = (EditText) findViewById(R.id.eTUser);
String usuario = user.toString();
pass = (EditText) findViewById(R.id.eTPass);
String passw = pass.toString();
String parametros = "?usuario=" + usuario + "&password=" + passw;
HttpGet httpGet = new HttpGet("http://gie.byethost.com/acces.php" + parametros);
Toast toast2 = Toast.makeText(getApplicationContext(), "Enviando datos", Toast.LENGTH_SHORT);
toast2.show();
try
{
response = client.execute(httpGet, localContext);
toast2 = Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT);
toast2.show();
}
catch (Exception e)
{
}
// response.toString();
if (response.toString().equalsIgnoreCase("1"))
{
Toast toast1 = Toast.makeText(getApplicationContext(), "Login correcto", Toast.LENGTH_SHORT);
toast1.show();
} else
if (response.toString().equalsIgnoreCase("0"))
{
Toast toast1 = Toast.makeText(getApplicationContext(), "Error de login", Toast.LENGTH_SHORT);
toast1.show();
}
}
}
这里只有一个按钮,并且没有烤面包显示,所以我看不到应用程序崩溃的位置。另外,我在Android编程方面有点新,所以这可能有一个明显的解决方案。
任何评论都将不胜感激!