Basic program termination


This question already has an answer here:


The program terminates because it takes the newline character the end-user added after the last integer as the end of the nextLine().

Let's say the user enters 123 and presses Enter. At this point, the data in the buffer looks like this:

[1] [2] [3] [\n]

After you call scan.nextInt() the integer part is removed, but the [\n] remains in the buffer. When you call scan.nextLine(), that end-of-line marker is the first character the scanner sees, so it treats that \n as an empty string, which is returned to your program. You can fix it by calling scan.nextLine() before taking a full-line input.

However, this by itself will not fix your program, because you should be comparing strings using equals(), e.g. like this

if (fc1.equals("A"))

not like this

if (fc1 == "A") // <<== This will not work correctly

Need Your Help

update data in listview using swipeRefreshLayout

android android-json

I am trying to update the data using swipeRefreshLayout, but every time I swipe down to refresh it is only circling but not refreshing.