0

I'm new in java, please help me to understand this.

I can see there is ReadHtml class and defined with one public method. But when i put this code in ecplise, it shows red mark under WebClient with tag that "this cannot resolved to a type". May I know what does it mean? Gone through all about method definition but couldn't find any remedy to understand this.

Can I get any help ?

public class ReadHtml {
    public static LinkedList<String> readJacksonCounty(String urlName, String pStartDate,String pFinishDate)
    {
        LinkedList<String> xmlListReturn=new LinkedList<String>();
        System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "error");
        final WebClient webClient1 = new WebClient(BrowserVersion.CHROME);
        webClient1.setJavaScriptTimeout(60000);
        webClient1.getCookieManager().setCookiesEnabled(true);//enable cookies
        webClient1.getCache().clear();
roy
  • 101
  • 1
  • 3
  • 9
  • 2
    You're lacking a library (import ....WebClient). Eclipse can import classes for you when you click Ctrl+Shift+O (Organize imports). If it is an external library, then first put the library on the build/class path (right click on your project Build Path->Configure BuildPath and under the Libraries tab add the need jar) – dsp_user Jan 10 '16 at 18:02

2 Answers2

1

You are missing an import of this library:

import com.gargoylesoftware.htmlunit.WebClient;

Add this to the top of your file (and read dsp_user's comment for future reference).

Idos
  • 15,053
  • 14
  • 60
  • 75
  • may I know from where I can download webclient library ? – roy Jan 10 '16 at 18:16
  • @roy sure, download it from here: http://sourceforge.net/projects/htmlunit/files/htmlunit/ – Idos Jan 10 '16 at 18:18
  • I have one more question hope you dont mind. Please correct me if am saying wrong. Here "final WebClient webClient1 = new WebClient(BrowserVersion.CHROME);" I believe we are creating object from method right ? If am right ..can you please explain me more..cos I'm not getting the clear image of using this. If am wrong please correct me. Thanks !! :) – roy Jan 10 '16 at 18:22
  • When you perform "new" you *instantiate* an object. By doing that, you are calling the *constructor* of that object. You are *passing it* the browser version (CHROME) and it *returns* an Object of *type* WebClient that you then *assign* to webClient1. :) Hope I was clear – Idos Jan 10 '16 at 18:23
  • Please check here, I have added the library like you said. But still same error exists ! http://prntscr.com/9off5u – roy Jan 10 '16 at 18:29
  • Try to rebuild your solution. It is definitely an import problem – Idos Jan 10 '16 at 18:30
  • Great, its gone. Can you Please check this sir....what happen with getoptions() method here ? http://prntscr.com/9ofigu – roy Jan 10 '16 at 18:36
0

Basically "...cannot be resolved to a type" means that type is not available on the class path. If you're just using eclipse refere to How to import a jar in Eclipse.

If you already added the needed jar onto your class path, you are missing the import statement. Imports just make it so that you dont have to use a class's fully qualified name. (you can type

 MyClass myClass;

as opposed to

 com.some.package.MyClass myClass;

if you add

 import com.some.package.MyClass;

at the top of your file.

Note that if you want to build a jar from your project you'll need some kind of build tool. If you choose to use Maven, which is very common, just read any tutorial on how to get started and manage dependencies.

DSantiagoBC
  • 464
  • 2
  • 11
aiguy
  • 671
  • 5
  • 20