字符串的子字符串不是字符串吗?

时间:2019-05-11 12:33:38

标签: java android algorithm

   String end = "1030";

   if(end.substring(2,4)=="30") {
                            end = Integer.toString(Integer.parseInt(end) - 30);
                            Log.d(TAG, "  ifif :  " + end);

                            resID = getResources().getIdentifier(date + end, "id", getActivity().getPackageName());
                            TextView textView = (TextView) view.findViewById(resID);
                            textView.setText(title);
                        }else{
                            end = Integer.toString(Integer.parseInt(end) - 100);
                            Log.d(TAG, "  ifelse :  " + end);

                            resID = getResources().getIdentifier(date + end, "id", getActivity().getPackageName());
                            TextView textView = (TextView) view.findViewById(resID);
                            textView.setText(title);
                        }

我希望应该转到if语句,但实际上应该转到else语句。

这是我的logcat。

2019-05-11 21:24:19.184 20873-20873 / com.example.a13.timetable4 D / TimeTableFragment:标题ab1开始:0900,32400000 /结束:1030,37800000 diff:5400000 min:90 / mok: 3

2019-05-11 21:24:19.184 20873-20873 / com.example.a13.timetable4 D / TimeTableFragment:substring(2,4):30

2019-05-11 21:24:19.184 20873-20873 / com.example.a13.timetable4 D / TimeTableFragment:ifelse:930

2019-05-11 21:24:19.185 20873-20873 / com.example.a13.timetable4 D / AndroidRuntime:关闭VM

--------- beginning of crash

2019-05-11 21:24:19.186 20873-20873 / com.example.a13.timetable4 E / AndroidRuntime:FATAL EXCEPTION:main        流程:com.example.a13.timetable4,PID:20873

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

您在日志中看到的不是“ ifif 930”,而是“ ifelse:930”

我的日志显示substring(2,4)是30,但是如果if语句(nd.substring(2,4)==“ 30”)则不起作用。

0 个答案:

没有答案