[英]System throws time out error during on click on login button
In my android java app, from the LoginActivity I am calling the "LoginRegisterWebService" restful webservice, but on click on the login button system throws a "Some error occured > com.android.volley.TimeOutError". 在我的Android Java应用程序中,我从LoginActivity调用了“ LoginRegisterWebService”静态Web服务,但是在单击登录按钮系统时,抛出了“发生了一些错误> com.android.volley.TimeOutError”。 Here I am using the Remix OS player emulator. 在这里,我正在使用Remix OS播放器模拟器。 Already gone through few answers related to volley timeout errors and increased the timeout duration, but it doesn't make any difference. 已经解决了与截击超时错误有关的几个问题,并增加了超时时间,但这没有任何区别。 Set the breakpoint in this step 'public void onResponse(String s)', but the system is not going inside onResponse. 在此步骤'public void onResponse(String s)'中设置断点,但是系统不会进入onResponse。 I have switched off the firewall too. 我也关闭了防火墙。 Could someone please help me to figure out the problem 有人可以帮我解决问题吗 Please find my Gradle settings 请找到我的Gradle设置
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.foodies.myfoodies"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.volley:volley:1.0.0'
testCompile 'junit:junit:4.12'
}
// LogingActivity code give below // LogingActivity代码如下
public class LoginActivity extends AppCompatActivity {
EditText emailBox, passwordBox;
Button loginButton;
TextView registerLink;
String URL = "http://[ip address]:8081/MyFoodies/LoginRegisterWebService/login";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
emailBox = (EditText)findViewById(R.id.emailBox);
passwordBox = (EditText)findViewById(R.id.passwordBox);
loginButton = (Button)findViewById(R.id.loginButton);
registerLink = (TextView)findViewById(R.id.registerLink);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringRequest request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>(){
@Override
public void onResponse(String rs) {
if(rs.equals("true")){
Toast.makeText(LoginActivity.this, "Login Successful", Toast.LENGTH_LONG).show();
startActivity(new Intent(LoginActivity.this,Home.class));
}
else{
Toast.makeText(LoginActivity.this, "Incorrect Details", Toast.LENGTH_LONG).show();
}
}
},new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(LoginActivity.this, "Some error occurred -> "+volleyError, Toast.LENGTH_LONG).show();;
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("email", emailBox.getText().toString());
parameters.put("password", passwordBox.getText().toString());
return parameters;
}
};
request.setRetryPolicy(new DefaultRetryPolicy(
7000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
RequestQueue rQueue = Volley.newRequestQueue(LoginActivity.this);
int socketTimeout = 10000;//10 seconds - change to what you want
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
request.setRetryPolicy(policy);
rQueue.add(request);
}
});
registerLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
}
});
}
}
//Following is the Webservice.java code //以下是Webservice.java代码
@Path("/LoginRegisterWebService")
public class LoginRegisterWebService {
final static String url = "jdbc:mysql://localhost:3307/foodhub";
final static String user = "root";
final static String pass = "root";
@POST
@Path("/login")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public String login(@FormParam("email") String email, @FormParam("password") String password){
String result="false";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
PreparedStatement ps = con.prepareStatement("select * from foodhub.login where email=? and UserPassword=?");
ps.setString(1, email);
ps.setString(2, password);
ResultSet rs = ps.executeQuery();
if(rs.next()){
result = "true";
}
con.close();
}
catch(Exception e){
e.printStackTrace();
}
return result;
}
@POST
@Path("/register")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)
public String register(@FormParam("email") String email, @FormParam("password") String password){
String result="false";
int x = 0;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, user, pass);
PreparedStatement ps = con.prepareStatement("insert into login(email, UserPassword) values(?,?)");
ps.setString(1, email);
ps.setString(2, password);
x = ps.executeUpdate();
if(x==1){
result = "true";
}
con.close();
}
catch(Exception e){
e.printStackTrace();
}
return result;
}
}
There can be multiple reasons that may cause this. 可能有多种原因导致此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.