CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13

Thread: HtmlUnit Help

  1. #1
    Join Date
    Jun 2011
    Posts
    9

    Exclamation HtmlUnit Help

    This is my first post in the forum. So I would also like to say hello to all.

    I am currently developing an application for Android and to do so I came across HtmlUnit.
    I have never heard of HtmlUnit so I decided to try it (me being the experimental type). I have come to an impasse.

    "noclassdeffounderror". Its awful because I do not fully understand it. It is my first time even seeing this error.

    Code:
    public void showResults(String endText) throws Exception{
        	WebClient webClient = new WebClient(); //ERROR IS HERE
        	HtmlPage page = webClient.getPage(baseSite+endText);
        	HtmlTable resultsT = page.getHtmlElementById("results");
        	int i = 0;
        	for(final HtmlTableRow row : resultsT.getRows()){
        		Toast.makeText(getApplicationContext(), "Getting Results...", Toast.LENGTH_SHORT).show();
        		for(final HtmlTableCell cell : row.getCells()){
        			results[i] = cell.asText();
        			i++;
        		}
        	}
        }
    What did I do wrong?

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: HtmlUnit Help

    Do you get the error when compiling or executing?
    Can you copy the full text of the message here?
    Norm

  3. #3
    Join Date
    Jun 2011
    Posts
    9

    Re: HtmlUnit Help

    I get the error while executing. There is no error while compiling. Thats why I am confused.

    Full error:
    Code:
    06-02 19:52:47.285: ERROR/AndroidRuntime(211): Uncaught handler: thread main exiting due to uncaught exception
    06-02 19:52:47.325: ERROR/AndroidRuntime(211): java.lang.NoClassDefFoundError: com.gargoylesoftware.htmlunit.WebClient
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.laytproducts.songmaster.mainAct.showResults(mainAct.java:109)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.laytproducts.songmaster.mainAct$1.onClick(mainAct.java:90)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.View.performClick(View.java:2364)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.View.onTouchEvent(View.java:4179)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.widget.TextView.onTouchEvent(TextView.java:6541)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.View.dispatchTouchEvent(View.java:3709)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.os.Handler.dispatchMessage(Handler.java:99)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.os.Looper.loop(Looper.java:123)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at android.app.ActivityThread.main(ActivityThread.java:4363)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at java.lang.reflect.Method.invokeNative(Native Method)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at java.lang.reflect.Method.invoke(Method.java:521)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    06-02 19:52:47.325: ERROR/AndroidRuntime(211):     at dalvik.system.NativeStart.main(Native Method)
    By the way, thanks for the reply.

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: HtmlUnit Help

    NoClassDefFoundError: com.gargoylesoftware.htmlunit.WebClient

    Do you have the above listed class in a jar file that is on the classpath?
    Norm

  5. #5
    Join Date
    Jun 2011
    Posts
    9

    Re: HtmlUnit Help

    I have it in a library labeled HtmlUnit.
    So yes.
    Pic just to make sure:

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: HtmlUnit Help

    Some how the JVM is saying it can't find the class???
    Norm

  7. #7
    Join Date
    Jun 2011
    Posts
    9

    Re: HtmlUnit Help

    Yeah I am confused as well.

  8. #8
    Join Date
    Jun 2011
    Posts
    9

    Re: HtmlUnit Help

    No one can help me? :P
    --bump--

  9. #9
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: HtmlUnit Help

    Is the jar file with the missing class on the classpath?

    Add something like the following to the main method to show what the classpath is.
    Use the log or where ever you output debug info to output it vs println
    Code:
          System.out.println("Classpath: " + System.getenv("classpath") 
                               + "\n java.class.path=" + props.getProperty("java.class.path") );
    Norm

  10. #10
    Join Date
    Jun 2011
    Posts
    9

    Re: HtmlUnit Help

    Ok will do so.
    Also noticed this in the beginning of my debug:
    Code:
    06-04 23:49:56.671: ERROR/dalvikvm(224): Could not find class 'com.gargoylesoftware.htmlunit.WebClient', referenced from method com.laytproducts.songmaster.mainAct.showResults
    06-04 23:49:56.671: WARN/dalvikvm(224): VFY: unable to resolve new-instance 14 (Lcom/gargoylesoftware/htmlunit/WebClient;) in Lcom/laytproducts/songmaster/mainAct;
    also, this is the results:
    Code:
    06-04 23:49:56.901: INFO/System.out(224): Classpath: null
    06-04 23:49:56.901: INFO/System.out(224):  java.class.path=null
    of this:
    Code:
    Properties props = new Properties();
            System.out.println("Classpath: " + System.getenv("classpath") 
                    + "\n java.class.path=" + props.getProperty("java.class.path") );

  11. #11
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: HtmlUnit Help

    You need to set the classpath to include your jars and the directory containing your package root.

    An excellent plumber is infinitely more admirable than an incompetent philosopher. The society that scorns excellence in plumbing because plumbing is a humble activity and tolerates shoddiness in philosophy because it is exalted activity will have neither good plumbing or good philosophy. Neither its pipes or its theories will hold water...
    J. Gardner
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  12. #12
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: HtmlUnit Help

    How do you put a class on the classpath in the Android environment?
    Norm

  13. #13
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: HtmlUnit Help

    Quote Originally Posted by Norm View Post
    How do you put a class on the classpath in the Android environment?
    I couldn't say - I guess they all have to go into the .apk file, but how that's done probably depends on your IDE. I've yet to dabble in Android development.

    This may be some help: My Life With Android - Jars on the classpath

    We make the road, others will make the journey...
    V. Hugo
    Last edited by dlorde; June 5th, 2011 at 02:39 PM.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured