ToxicGlow
ToxicGlow

Reputation: 71

"Cannot be resolved to type" error

So here is a code I wanted to test..(This is for understanding how to convert to CSV file)

String csv = "C:\\output.csv";
CSVWriter writer = new CSVWriter(new FileWriter(csv));

String [] country = "India#China#United States".split("#");

writer.writeNext(country);

writer.close();

Here is the class I imported , import au.com.bytecode.opencsv.CSVWriter; , I made sure the path is built.

Im trying out that code so I can understand its working but its confusing me now.

ANY sort of help is appreciated. I know there are so many similar questions, I did have read through some and got confused.

I am getting CSVWrite cannot be resolved to type.

Here is my ENTIRE code:

I am learning how to take content off web and convert it into a csv file.

import java.net.*;
import java.io.*;
import au.com.bytecode.opencsv.CSVWriter;

public class InfoGather {

    private static BufferedWriter out;
    /*private static String csv;
    private static BufferedReader csvin;*/

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

        try{
            URL blog = new URL("http://protectidentite.blogspot.ca/2014/02/mobile-phones-are-one-of-most-popular.html");
            URLConnection connect= blog.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream()));

            FileWriter fstream = new FileWriter("out.txt");
            out = new BufferedWriter(fstream);

            String inputLine;
            while((inputLine = in.readLine())!= null)
            {
            out.write(inputLine);
            out.newLine();
            }
          /*  csv = "C:\\output.csv";

            csvin = new BufferedReader(new FileReader("out.txt")); */

            String csv = "C:\\output.csv";
            CSVWriter writer = new CSVWriter(new FileWriter(csv));

            String [] country = "India#China#United States".split("#");

            writer.writeNext(country);

            writer.close();
        }
        catch(IOException e)
        {
            System.out.println("error");
        }
    }

}

Majority of it is taken from the web. I also created another class which generates an excel file.

Upvotes: 0

Views: 7676

Answers (1)

Sachin Verma
Sachin Verma

Reputation: 3812

Looks like you don't have clear understanding about import statement. Basically there are Java's own libraries means many many jars containing many many classes, by default, only those are accessible to JVM. So using import we can contact with any class that is inside those jars.

If you want to use a class that is not from default java libraries you need to add the jar that contains that class and after jvm is able to contact that class then you need to import that class by import a.b.c.d.CSVWriter.

Make sense?

Upvotes: 2

Related Questions