Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:If语句被跳过,即使条件正确_Java_Php_Android_Mysql_If Statement - Fatal编程技术网

Java Android:If语句被跳过,即使条件正确

Java Android:If语句被跳过,即使条件正确,java,php,android,mysql,if-statement,Java,Php,Android,Mysql,If Statement,我是android新手,正在创建一个注册页面。由于android不支持mysql,我创建了一个基于php的脚本,为不同的查询提供整数值 2 --> successful insertion in database -1 --> Email already used 0--> username used 根据从php脚本获得的响应的整数值,我执行后续任务。即使成功地在数据库中插入了这些值,并且第一个打印语句将Regresult的值显示为“2”,但if语句不起作用,而else i

我是android新手,正在创建一个注册页面。由于android不支持mysql,我创建了一个基于php的脚本,为不同的查询提供整数值

2 --> successful insertion in database
-1 --> Email already used
0--> username used
根据从php脚本获得的响应的整数值,我执行后续任务。即使成功地在数据库中插入了这些值,并且第一个打印语句将Regresult的值显示为“2”,但if语句不起作用,而else if语句和else if语句都起作用

/* Getting the response back from the PHPAPI and storing it in a variable */
HttpEntity entity = Response.getEntity();
String Regresult = EntityUtils.toString(entity);


/* printing value of Regresult to verify if the condition is right or wrong */
System.out.println(Regresult);

/* Registration depending upon response from Http post call */       
/* Email used works fine when Regresult = -1 */

if(Regresult.equals("-1"))
{
     Context text = getApplicationContext();
     CharSequence message = "Email already in use.";
     int duration = Toast.LENGTH_SHORT;
     Toast toast = Toast.makeText(text, message, duration);
     toast.show();
 }

 /* Username used work fine when Regresult = 0 */

 else if(Regresult.equals("0"))
 {
      Context text = getApplicationContext();
      CharSequence message = "Username already in use.";
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(text, message, duration);
      toast.show();
 }  

/* Here is the problem when Regresult= 2 , even though consition is correct the statement don't get executed */
 else if(Regresult.equals("2"))
 {
      Context text = getApplicationContext();
      CharSequence message = "Registration Successful.";
      int duration = Toast.LENGTH_SHORT;
      Toast toast = Toast.makeText(text, message, duration);
      toast.show();
      System.out.println(Regresult);
 }
// I think it may be some spacing problem so try this way
        if(Regresult.trim().equals("-1")){
            Context text = getApplicationContext();
            CharSequence message = "Email already in use.";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(text, message, duration);
            toast.show();
        }else if(Regresult.trim().equals("0")){
            Context text = getApplicationContext();
            CharSequence message = "Username already in use.";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(text, message, duration);
            toast.show();
        }else if(Regresult.trim().equals("2")) {
            Context text = getApplicationContext();
            CharSequence message = "Registration Successful.";
            int duration = Toast.LENGTH_SHORT;
            Toast toast = Toast.makeText(text, message, duration); toast.show();
        }