Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Java
public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    
    System.out.print("Enter member id to search : "); 
    String search = scanner.nextLine();
    for (int i = 0; i < v.length; i++) {
        if (search.equals(v[i].getMemID())) { // String comparison 
            System.out.println(v[i].toString());
            System.out.print("Enter your Name");							
            String memName = scanner.nextLine();
            v[i].setmemName(memName);
        } 
    }
}
Posted
Updated 31-Jul-14 20:52pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Aug-14 0:06am    
By the debugger.
—SA
Richard MacCutchan 1-Aug-14 2:52am    
Which is line 342?
Member 10452585 1-Aug-14 3:48am    
String search = scanner.nextLine();

Richard MacCutchan 1-Aug-14 4:12am    
I have tried various inputs using that code and cannot get it to fail. i suspect the error is really occurring somewhere else or there is some other code that you have not shown us.
Member 10452585 1-Aug-14 9:17am    
When i remove the coding they have no problem , then problem is in line 342 (if (search.equals(v[i].getMemID()))
)

1 solution

Debugging with Eclipse - Tutorial by Lars Vogel[^]

When
Java
String search = scanner.nextLine();


produces an Exception, then must scanner == null or scanner.nextLine() == null .
A Short look in the debugger would give you the answer.

you can
- use try/catch
- use an if-statement
- make sure the data is not null


Have fun!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900