Hi all, I have just started to learn java.
The trial code I have is showing errors at compiling.
Here is the code.

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.Scanner;

    public class ppp {


        public static void main(String args[]) throws FileNotFoundException  {



           //Scanner Example - read file line by line in Java using Scanner
            FileInputStream fis = new FileInputStream("C:/sample.txt");
            Scanner scanner = new Scanner(fis);

            //reading file line by line using Scanner in Java
            //System.out.println("Reading file line by line in Java using Scanner");

            while(scanner.hasNextLine()){
                System.out.println(scanner.nextLine());

        String assetClasses = scanner.nextLine();
        String[] splits = asseltClasses.split("\t");

        System.out.println(scanner.nextLine());
        System.out.println("splits.size: " + splits.length);
        for(String asset: assetClasses){
    System.out.println(asset);
    }

            }

            scanner.close();
        }   

    }




Below is the errors.
ppp.java:29: cannot find symbol
symbol  : variable asseltClasses
location: class ppp
        String[] splits = asseltClasses.split("\t");
                          ^
ppp.java:33: foreach not applicable to expression type
        for(String asset: assetClasses){
                          ^
2 errors

Pl help.

Regards,
Madiya

You spelled "asset" wrong, for one thing. For another, I suspect you wanted to use splits in the foreach loop rather than assetClasses.

Hi,
Thanks for reply.
I have changed asseltClasses to assetClasses.
so first error is resolved.
But still getting 2nd error 33 for foreach one.
I am trying to read a text file, line by line and then split the string with \t and again print each splited string. so using split in foreach loop.
Pl suggest.

Thanks.
Madiya

deceptikon already told you how to fix that.
you are running a for-each on assetClasses, which is not an array, but a single String.
replace that by
for ( String asset : splits )

Comments
Thanks. It helped to take out 2nd error.

OK, so while there is a next line available, you do this:

You read a line of data, print it, and throw it away.

Then you read another line of data, store it in "assetClasses", split it into fields, that were separated by tabs, and put the fields into "splits".

Then you read a third line, print it and throw it away.

Then you print the number of fields (from the second line you read), and then print each of the fields.

Then you go back and read three more lines -- "processing" only the second of the three lines.

Yep; that's what your program is doing.

Is this different than what you want it to be doing? ;-)

JeffGrigg,
Thank you very much for reply.
Actually I am trying to read each line and print it.
Then split each line with tab as delimiter and print each splitted parts.
Now read 2nd line. Print it, split it, print splited parts.
The next line i.e. 3rd line.
I tried hard but could not gauge where I am mistaking.
Thanks for help.

Beginer - Error can not find symbole
JeffGrigg,
Thank you very much for reply.
Actually I am trying to read each line and print it.
Then split each line with tab as delimiter and print each splitted parts.
Now read 2nd line. Print it, split it, print splited parts.
The next line i.e. 3rd line.
I tried hard but could not gauge where I am mistaking.
Here is my updated code.

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.util.Scanner;


    public class ppp {


        public static void main(String args[]) throws FileNotFoundException  {

           //Scanner Example - read file line by line in Java using Scanner
            FileInputStream fis = new FileInputStream("C:/sample.txt");
            Scanner scanner = new Scanner(fis);

            //reading file line by line using Scanner in Java
            System.out.println("Reading file line by line in Java using Scanner");

            while(scanner.hasNextLine()){
        string tt = scanner.nextLine();//this is error line
                System.out.println(tt);
        String assetClasses = tt;
        String[] splits = assetClasses.split("\t");

        System.out.println(tt);
        System.out.println("splits.size: " + splits.length);


        for(String asset: splits){
            System.out.println((splits));
            }

            }

            scanner.close();
        }   

    }
    Getting error as below.
    ppp.java:19: cannot find symbol
    symbol  : class string
    location: class ppp
            string tt = scanner.nextLine();

Pl help.
Thanks again.
Thanks for help.

Java is case-sensitive. string and String are not the same. String is a class name and is spelled with a capital S

Comments
Thanks for pointing out. Really appreciate it.

Hi all,
Sorry to bother you all.
All issue sorted out.
It was a silly capitalisation error while declaring string as oppose to String.

Thanks any way for all the support you have provided.

Regards,
Madiya

Comments
Thank you for letting us know that you solved the problem and how.
This question has already been answered. Start a new discussion instead.