Take the 2-minute tour ×

I'm getting an debugging error at String.charAt(int) line: not available for the line
ch = Ach.charAt(0);

char ch;
String Ach;    
Scanner input = new Scanner(System.in);
printvehicleMAKE(services, input);

        System.out.println("\n    Service Item Recording Feature");
        System.out.println("\n\n A - Record Part Details");
        System.out.println("\n B - Add Labour Hours");
        System.out.println("\n X - Exit service item recording feature");
        System.out.print("\n\nEnter your selection: ");
        Ach = input.nextLine().toUpperCase();
        ch = Ach.charAt(0);
            case 'A':
                System.out.print("Enter registration number of vehicle: ");
                String inputREGO = input.nextLine();
                boolean flag = false;
                        System.out.print("Enter Part Description: ");
                        String parts = input.nextLine();
                        System.out.print("Enter Part Cost: ");
                        Double cost = input.nextDouble();
                        services[i].addPARTDETAILS(parts, cost);
                        flag = true;
                    System.out.println("No registration number were found in the system.");

            case 'B' :
            case 'X' :
                System.out.println("Exiting system......");
            default: System.out.println("Error - invalid selection entered!");

public static void printvehicleMAKE(ServiceAppointment[] services, Scanner
    System.out.print("Enter vehicle make: ");
    String make = input.nextLine();
    boolean flag = false;
        if (services[i].getvehicleMAKEMODEL().indexOf(make) != -1){
            System.out.printf("\n%-10s%-8s%10s", services[i].getregoNUMBER(),
                    services[i].getbuildYEAR(), services[i].getvehicleMAKEMODEL());
        System.out.println("No service appointments were found for vehicles " 
                + "made by " + make);

share|improve this question
And the question is...? –  Ted Hopp Apr 8 '13 at 16:01
And the error is...? –  Charles Forsythe Apr 8 '13 at 16:02
Please post the error message -- copy paste. And be sure to include relevant line identifications. –  Hot Licks Apr 8 '13 at 16:02
are you sure Ach string is not null? –  Stephan Apr 8 '13 at 16:03
The first part of your code (before the printvehicleMAKE method) is not within a method. –  assylias Apr 8 '13 at 16:06
add comment

closed as not a real question by Bohemian, Frank Schmitt, Emil Vikström, Guru, Tim Bish Apr 8 '13 at 19:03


1 Answer

up vote 0 down vote accepted

If the question is why the line number is not available, that is probably a function of how you have packaged up your code for execution. It sounds like the debug info has been stripped.

if the question is what might be wrong with your code at that line, the answer is that Ach may have zero length (if the input was an empty line). Hence Ach.charAt(0) will fail because there is no first character. You need to test for that condition.

ch = Ach.length() > 0 ? Ach.charAt(0) : '\n';
share|improve this answer
It looks like his code is not within a method. –  assylias Apr 8 '13 at 16:06
@assylias - It looks like that, but I suspect OP just left out the context for this code (or the post has a typo). If it were not within a method, the code would not compile and OP wouldn't have gotten as far as using the debugger. –  Ted Hopp Apr 8 '13 at 16:08
Unless he is getting a compile error - and calls it a debugging error? Just speculating... –  assylias Apr 8 '13 at 16:09
@assylias - Perhaps so, but it would be a weird compiler that generates an error but doesn't know the line number. Also, if the problem is that there is no enclosing method, why would the compiler complain about a line that is so far into the code? –  Ted Hopp Apr 8 '13 at 16:16
add comment
