Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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操作系统_Java_Android - Fatal编程技术网

<;=&&>;=Java/Android操作系统

<;=&&>;=Java/Android操作系统,java,android,Java,Android,我对这段代码有问题。它总是在“你在博物馆外面或者再次检查你的位置”的祝酒词上:你认为问题出在哪里?代码如下: x3 = x3 * -1; //for example is 187 y3 = y3 * -1;//for example is 698 ImageView img = (ImageView) findViewById(R.id.imageView1); if(((x3 <= 150) && (x3 >= 170)) &am

我对这段代码有问题。它总是在“你在博物馆外面或者再次检查你的位置”的祝酒词上:你认为问题出在哪里?代码如下:

    x3 = x3 * -1; //for example is 187
    y3 = y3 * -1;//for example is 698

    ImageView img = (ImageView) findViewById(R.id.imageView1);

    if(((x3 <= 150) && (x3 >= 170)) && ((y3 <= 680) && (y3 >= 725))){
        img.setImageResource(R.drawable.map_1_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 1", Toast.LENGTH_LONG).show();
        currentSection = "sect_1";
    }else if(((x3 <= 170) && (x3 >= 195)) && ((y3 <= 690) && (y3 >= 715))){
        img.setImageResource(R.drawable.map_2_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 2", Toast.LENGTH_LONG).show(); //this suppost to be the output
        currentSection = "sect_2";
    }else if(((x3 <= 200) && (x3 >= 230)) && ((y3 <= 680) && (y3 >= 720))){
        img.setImageResource(R.drawable.map_3_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 3", Toast.LENGTH_LONG).show();
        currentSection = "sect_3";
    }else if(((x3 <= 190) && (x3 >= 220)) && ((y3 <= 675) && (y3 >= 710))){
        img.setImageResource(R.drawable.map_4_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 4", Toast.LENGTH_LONG).show();
        currentSection = "sect_4";
    }else if(((x3 <= 175) && (x3 >= 219)) && ((y3 <= 710) && (y3 >= 745))){
        img.setImageResource(R.drawable.map_5_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 5", Toast.LENGTH_LONG).show();
        currentSection = "sect_5";
    }else if(((x3 <= 155) && (x3 >= 165)) && ((y3 <= 715) && (y3 >= 735))){
        img.setImageResource(R.drawable.map_6_full_lite);
        Toast.makeText(getBaseContext(), "You're currently on Section 6", Toast.LENGTH_LONG).show();
        currentSection = "sect_6";
    }else{
        Toast.makeText(getBaseContext(), "You're outside of the museum or Check your postion again", Toast.LENGTH_LONG).show();
    }
x3=x3*-1//例如187
y3=y3*-1//例如698
ImageView img=(ImageView)findViewById(R.id.imageView1);
如果((x3=170))&((y3=725))){
img.setImageResource(R.drawable.map\u 1\u full\u lite);
Toast.makeText(getBaseContext(),“您当前在第1节”,Toast.LENGTH_LONG.show();
currentSection=“sect_1”;
}否则如果((x3=195))和((y3=715))){
img.setImageResource(R.drawable.map\u 2\u full\u lite);
Toast.makeText(getBaseContext(),“您当前在第2节”,Toast.LENGTH_LONG.show();//此支持将作为输出
currentSection=“sect_2”;
}否则如果((x3=230))和((y3=720))){
img.setImageResource(R.drawable.map\u 3\u full\u lite);
Toast.makeText(getBaseContext(),“您当前在第3节”,Toast.LENGTH_LONG.show();
currentSection=“sect_3”;
}否则如果((x3=220))和((y3=710))){
img.setImageResource(R.drawable.map\u 4\u full\u lite);
Toast.makeText(getBaseContext(),“您当前在第4节”,Toast.LENGTH_LONG.show();
currentSection=“sect_4”;
}否则如果((x3=219))和((y3=745))){
img.setImageResource(R.drawable.map\u 5\u full\u lite);
Toast.makeText(getBaseContext(),“您当前在第5节”,Toast.LENGTH_LONG.show();
currentSection=“sect_5”;
}否则如果((x3=165))和((y3=735))){
img.setImageResource(R.drawable.map\u 6\u full\u lite);
Toast.makeText(getBaseContext(),“您当前在第6节”,Toast.LENGTH_LONG.show();
currentSection=“sect_6”;
}否则{
Toast.makeText(getBaseContext(),“你在博物馆外面或者再次检查你的位置”,Toast.LENGTH_LONG.show();
}

这是因为您的语句

(x3 <= 150) && (x3 >= 170)
(x3=170)
不可能是真的

你是说这个吗

(x3 <= 150) || (x3 >= 170)
(x3=170)
这是不可能的

(x3 <= 150) && (x3 >= 170)
(x3=170)
原样

(x3=195)
x3不能小于或等于150,也不能大于或等于170。我怀疑你是有意这样做的

(150 <= x3) && (x3 <= 170)

(150您的条件总是
false
。只需考虑:

((x3 <= 155) && (x3 >= 165)) && ((y3 <= 715) && (y3 >= 735))
((x3=165))和((y3=735))
&&
运算符是
意味着该运算符两侧的两个条件都必须为真才能使整个表达式为真。现在不难发现,对于
x3
的任何值,条件
(x3=165)
为假。因此,该条件永远无法满足

if
的每个分支都具有该属性,因此最后选择了
else
分支


我认为您已经混合了
=
(大于或等于)运算符。所有值,例如
x3
,都应该在某个范围内(即房间边界坐标),就像在上述情况下
x3
应该在
(x3>=155)&&(x3 x3不能同时小于150和大于170。我还想提及的是,该程序从来没有说“你在博物馆外面或再次检查你的位置”。你的意思是| |在你上次的声明中,不是吗?更正了。我的意思是
x3
介于[150170]之间我假设他有用户可以点击的瓷砖。逻辑是,如果x3=187(例如)在150x到170x之间,而y3=693(例如)在690y到715y之间,那么该坐标就在该部分上。类似于:OhOh 187在150到170之间?我将把它写成
150
(170 <= x3) && (x3 <= 195)
((x3 <= 155) && (x3 >= 165)) && ((y3 <= 715) && (y3 >= 735))