Errors that require assistance in compiling basic Java programs

I'm new to Java I'm having trouble compiling basic Java programs, and I'm trying to understand why (note that the TEXTIO class in the code is used in the book I'm studying to simplify the IO process. I don't believe that's the problem.) this is my code:

public class ProcessSales {
    public static void main(String[] args) {

        String      ln;
        String      tmp;
        int         i;
        int         noval;

        TextIO.readFile("sales.dat");

        while (TextIO.eof() == false){
            ln = TextIO.getln();
            for (i = 0; i < ln.length(); i++) {
                if (ln.charAt(i) == ':'){
                    tmp = ln.subString(i + 1);  
                }   
            } // end line for loop

            try {
                System.out.printf("%8.2f\n",Double(tmp.trim()));
            }
            catch (NumberFormatException e) {
                novaL++;
            }
        } // end of file while loop

        System.out.printf("\nThere were a total of %d cities that didnt have data\n",noval); 

    } // end of main subroutine
} // end of ProcessSales class

The compilation errors I get are as follows:

[seldon@PrimeRadiant Exercises]$javac ProcessSales.java
ProcessSales.java:15: cannot find symbol
symbol  : method subString(int)
location: class java.lang.String
                    tmp = ln.subString(i + 1);  
                            ^
ProcessSales.java:20: cannot find symbol
symbol  : method Double(java.lang.String)
location: class ProcessSales
                System.out.printf("%8.2f\n",Double(tmp.trim()));
                                             ^
2 errors

I have declared ln as a string object For string objects, the substring method is directly outside the Java API I don't understand why I can't find a symbolic compilation error, especially if it lists the method signature and the location below the error

I mark these problems as home work because I'm writing a textbook. I want to understand this problem, not a flat solution However, this is self-study, not part of any practical course (now)

Solution

The benefit of the java compiler is that it provides you with a lot of information that can be used to determine the location of problems in your code For you, the first question is here:

tmp = ln.subString(i + 1);

In this case, you capitalize a letter you shouldn't have It should be:

tmp = ln.substring(i + 1);

Whenever you see the compiler output "unable to find symbol", because the java compiler cannot find a method matching the output name, this may be due to syntax error or lack of dependency For your second question, you didn't release the corresponding code, but I can see from the error message that you lack new keywords

System.out.printf("%8.2f\n",Double(tmp.trim()));

should

System.out.printf("%8.2f\n",new Double(tmp.trim()));

If this is not your first programming language, I recommend using an IDE like eclipse because it provides you with autocompletion and syntax checking This is a good tool to quickly learn the API of the language However, if Java is your first programming language, please continue without holding your hand, because these difficulties will consolidate the lessons faster

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>