繁体   English   中英

如果不执行位置

[英]If not executing with location

我有一个if陈述,检查以确保邮政编码与我们服务的区域匹配,但是当我在邮政编码中时,我正在测试If是否运行。 请告诉我我在做什么错

String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
            String city = addresses.get(0).getLocality();
            String state = addresses.get(0).getAdminArea();
            String country = addresses.get(0).getCountryName();
            String postalCode = addresses.get(0).getPostalCode();
            String knownName = addresses.get(0).getFeatureName();
            // final TextView mTextView = (TextView) findViewById(R.id.location);
            //mTextView.setText("Latitude "+latitude+" Longitude "+longitude);
            final TextView mAdressTextView = (TextView) findViewById(R.id.addressNum);
            mAdressTextView.setText(address);
            final TextView mStateTextView = (TextView) findViewById(R.id.stateNum);
            mStateTextView.setText(city+ ", "+ state+", " + postalCode);

            if (postalCode == "33331"){
                Intent logoutDone = new Intent(MainActivity.this, Register.class);
                startActivity(logoutDone);
                Log.d("ADebugTag", "Value: " + postalCode);
            }

我不确定if的意思是不运行,但是这个答案可能会有所帮助。

在Java中,==比较对象的引用。 您的目标是查看postalCode字符串对象是否持有“ 33331”。 所以你想这样做:

if(postalCode.equals("33331"))
{
   // do stuff
}

如果要查看两个对象是否是同一实例,可以使用==代替。 当您要比较两个字符串的值时,需要像上面一样使用equals()方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM