From: RBRi <rb...@us...> - 2018-05-27 08:42:51
|
For mee this lookl like a classpath problem. Please make sure you have all the dependencies only once in your classpath and in the correct version. Outside of this, version 2.12 is really outdated. We can only support the latest version. > When I importet the newest version of HtmlUnit in Android-Studio an error occurred Mabe you can report the error you got --- ** [feature-requests:#253] App crashes when I want to get a website using HtmlUnit** **Status:** open **Group:** 2.31 **Labels:** android runtime-error java htmlunit html android studio **Created:** Sat May 26, 2018 01:15 PM UTC by Venatorc Coolerfigo **Last Updated:** Sat May 26, 2018 01:15 PM UTC **Owner:** nobody For my app I want to get the html-text of a website. But the dynamic text on my website is written in JavaScript, so I wrote a Java-programm where I get the text using "HtmlUnit". Now I want to display this text in my android app. When I importet the newest version of HtmlUnit in Android-Studio an error occurred. I solved it by implementing an older version of HtmlUnit into the build.gradle: ~~~ dependencies { implementation 'net.sourceforge.htmlunit:htmlunit:2.12' } ~~~ I also added "internet-permission" to the AndroidManifest.xml. Then I tried using HtmlUnit like in Java, but when I try to launch the app, it immediately crashes. The code of my "MainActivity.java" is the following: ~~~ package com.example.test.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; import java.io.IOException; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebClient webClient = new WebClient(); try { final HtmlPage page = webClient.getPage("https://www.google.com/"); } catch (IOException e) { e.printStackTrace(); } } } ~~~ Without final HtmlPage page = webClient.getPage("https://www.google.com/"); the app starts perfectly without any errors. As soon as I add this code, the app doesnt start properly and when I use the debugger, the following errors occur (I put it into "code-style" so it can be read better): ~~~ E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.test.myapplication, PID: 8543 java.lang.IncompatibleClassChangeError: Superclass org.apache.http.conn.scheme.PlainSocketFactory of com.gargoylesoftware.htmlunit.SocksSocketFactory is declared final (declaration of 'com.gargoylesoftware.htmlunit.SocksSocketFactory' appears in /data/app/com.example.test.myapplication-2/split_lib_dependencies_apk.apk) at com.gargoylesoftware.htmlunit.WebClient.createWebConnection(WebClient.java:2123) at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:129) at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:182) at com.example.test.myapplication.MainActivity.onCreate(MainActivity.java:18) at android.app.Activity.performCreate(Activity.java:6912) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985) at android.app.ActivityThread.-wrap14(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6692) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) ~~~ Do I have to change the HtmlUnit-code? I already tried it but the code is "readonly". Or what can I do/use otherwise? (Maybe I have an error in my code?) Thank you in advance! Venatorc PS. I have already tried to declare HtmlPage page as not final. --- Sent from sourceforge.net because htm...@li... is subscribed to https://sourceforge.net/p/htmlunit/feature-requests/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/feature-requests/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |