-1

I could use a few pointers, new to Java.

I am using a function that returns a "Reader" type. Documented here:

http://docs.oracle.com/javase/6/docs/api/java/io/Reader.html?is-external=true

Here are my lines of code:

Reader test = null;

test = WWIO.openReader("http://google.com");

The second line is okay, but the first puts an error on "Reader" saying

Reader cannot be resolved to a type

Why is that? I have

import java.lang.Object;

Which I don't even think is necessary? Why doesn't the compiler understand the type?

4

4 回答 4

7

While

 import java.lang.Object;

really is not necessary, you need to include

 import java.io.Reader;    
于 2013-06-12T16:08:15.973 回答
3

Import the reader using

import java.io.*;

The compiler excludes unused imports, so using the asterisk won't have any negative effect.

More direct is obviously

import java.io.Reader;

于 2013-06-12T16:08:05.287 回答
3

You should have

import java.io.Reader;

Importing java.lang.Object is completely unnecessary. Actually, importing every class from the java.lang.* package is unnecessary, since they're imported by default.

于 2013-06-12T16:08:33.537 回答
3

In Eclipse, pressing CTRLSHIFTO may help a lot ;)

Since java.io.Reader is under the package java.io, you need to import that package.

import java.io.Reader; 

or

import java.io.*;

Alternatively, you can qualify it directly in the code:

java.io.Reader test = null;

(that is useful when you need to use two different classes with the same name)

Note that java.lang package is automatically available, so there is no need to import it.

于 2013-06-12T16:09:50.773 回答