Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem in using HtmlUnit

843789Apr 27 2009 — edited Apr 29 2009
Hi All,
I am using HtmlUnit for posting the data to the server for handling the interactive websites. But for some of the sites I got the exception "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space".
For other sites the code is working prooperly. My code is as below with the URL which is giving exception.
import java.util.List;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import java.io.File;
import java.io.PrintWriter;

public class test_html 
{
public static void main(String[] args) throws Exception 
{
            WebClient webClient =null;
            HtmlPage page=null;
            HtmlForm form=null;
            int newMessageCount = 0;
            PrintWriter pw=null;
                        
            pw=new PrintWriter(new File("file_html.txt"));
            webClient=new WebClient(BrowserVersion.FIREFOX_3);
            webClient.setThrowExceptionOnScriptError(false);
            webClient.setJavaScriptEnabled(false);
            page= (HtmlPage) webClient.getPage("http://www.msnbc.msn.com/id/3053415/deck/tmobile");
            form= page.getFormByName("fgl");	   
            form.getInputByName("txtZip").setValueAttribute("12345");
            page = (HtmlPage) form.getButtonByName("ZipSubmit").click();
                
            pw.write(page.asText());
            pw.close();
       }
}
Please help me to solve this exception.

Thanks & Regards,
Jyotin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2009
Added on Apr 27 2009
1 comment
323 views