Has anybody gotten HTMLUnit (or HtmlUnitDriver) to work on Android apps?
This is the problem: I am getting the following error message:
11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule
This is what I did: I tried adding adding references to the jars listed in the following link (under both Project Dependencies and Project Transitive Dependencies - compile only, excluding test jars):
http://htmlunit.sourceforge.net/dependencies.html
However Eclipse kept crashing, then I found a few questions saying some jars are already contained in the Android SDK:
xalan, xercesImpl and xml-apis
HtmlUnit on Android
HttpClient
Android Programming HtmlUnit
So I removed the references to these jars keeping only the following:
commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-io-2.0.1.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
cssparser-0.9.5.jar
htmlunit-2.9.jar
htmlunit-core-js-2.9.jar
httpmime-4.1.2.jar
nekohtml-1.9.15.jar
sac-1.3.jar
httpcore-4.1.3.jar
It was at this point when the app was able to run but when the following line of code was executed I started to get the error:
final WebClient webClient = new WebClient();
11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule
I did a web search and found that xml-apis-1.3.04.jar contains org/w3c/dom/css/CSSRule so I put that reference back to the project but the app wouldn't build at all saying the same error message described in the first link above:
[2011-11-26 16:39:52 - Myproj] Conversion to Dalvik format failed with error 1
Could somebody please shed some light on this?
xml-apis-1.3.04.jar contains core classes. You have to modify the jar and delete those classes.
Please note that, at least in current ADT version, you are getting a message explaining the problem:
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.
Just as ULsies stated in the comments Htmlunit does this ==> HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.
which is exactly similar to webview widget provided inside the android sdk you dont need any other extra jar to open a web page inside your activity
as per google android documentation
A WebView is a View that displays web pages.It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.
add this to your activity layout xml file.
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
and this to your activity class file..
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.your url .com");
more on this here: http://developer.android.com/guide/webapps/webview.html
Related
I am trying to run this example. I reached upto "Modify the Client Application" and I am then having the following errors (and below is my file organization screenshot:
At this stage, as you can see below, I have the following issues in MainActivity.java.
activity_main.xml is called out but the project in its layout folder only has activity_register.xml (see here)
"Checkinendpoint" class is undefined but there is a CheckInEndPoint.java in the "MobileAssistant-AppEngine" project, as you can see in the image below. Is that not supposed to get picked up in MainActivity.java - how to import that? (doesnt work like a normal library import, i.e. "MobileAssistant-AppEngine" is not a library that "MobileAssistant" can reference.
Same question as above for CheckIn class that is also undefinted in the picture below.
Delete deviceinfoendpoint-v1-generated-source & messageendpoint-v1-generated-source from the Project-MobileAssistant and then right click on the MobileAssistant-appengine project then click on Generate Cloud EndPoint Library from Google Sub menu.
I'm trying to develop app working with YouTube. First, I downloaded gdata libs from
https://code.google.com/p/gdata-java-client/downloads/list (client, core, media and youtube), then tried to instantiate YouTubeService as in Google's tutorial:
service = new YouTubeService(id, key);
But when I tried to launch my app I got this:
ERROR/dalvikvm(5289): Could not find class 'com.google.gdata.data.media.MediaStreamSource', referenced from method com.google.gdata.client.media.MediaService.getMediaResource
ERROR/dalvikvm(5289): Could not find class 'com.google.gdata.data.media.MediaMultipart', referenced from method com.google.gdata.client.media.MediaService.insert
ERROR/AndroidRuntime(5289): FATAL EXCEPTION: main
java.lang.VerifyError: com/google/gdata/client/media/MediaService
libs are attached to project and I can see those "missing" classes in them, and my IDE can see them, but there's something strange happens in runtime. Any ideas where I'm spoiled?
P.S. It's Android app, if it matters.
Solve the probem by adding the following libraries:
activation.jar
additionnal.jar
android-support-v4.jar
guava-r07.jar
mail.jar
beside the gdata libraries:
gdata-client-1.0.jar
gdata-core-1.0.jar
gdata-media-1.0.jar
gdata-youtube-2.0.jar
Not need authetntication.
Any "Use Scala on Android" tutorials I find only show to make a simple "Hello World" app. Has anyone actually succeeded in using a Scala library jar in a real life Android app?
I tried to use goose library (https://github.com/GravityLabs/goose/) in my Android project. I built goose-2.1.22.jar from the sources fine. Inserted it into libs directory of my Android project, and added some code to test what will happen:
String url = "http://www.cnn.com/2010/POLITICS/08/13/democrats.social.security/index.html";
Configuration cfg = new Configuration();
Goose goose = new Goose(cfg);
com.gravity.goose.Article article = goose.extractContent(url);
String s = article.cleanedArticleText().toString();
The project compiled fine, no complains. When I try to run it though, I get an exception:
java.lang.NoClassDefFoundError: com.gravity.goose.Configuration
A little bit better after adding scala-for-android.jar to libs form "Scala for Android" project, or scala-library.jar from the latest stable Scala - then I get:
java.lang.ExceptionInInitializerError
at com.gravity.goose.Configuration.<init>(Configuration.scala:77)
at com.hyperionics.ScalaTest.TestActivity$1.onClick(TestActivity.java:31)
Is there some trick to make it work?
More information: the crash is in Configuration.scala file of goose, on exactly this line:
var contentExtractor: ContentExtractor = StandardContentExtractor
I added all the jars from Scala distribution lib directory to my project after a period of testing, but there is no difference, same crash. Also found "Scala for Android" project at http://code.google.com/p/scalaforandroid/ and added it's jars instead of the ones from standard Scala distro, no difference. To compile my project and go around the error "Android Dex: Too meny methods ..." I had to use DexGuard, as with Proguard again I was getting weird errors.
Any more tips on how to make this work would be much appreciated!
I am currently developing an Android app using cordova 2.0. Obviously the plugins.xml has been depreciated and everything is now housed in config.xml. I was just wondering if anyone has managed to get the Phonegap Screenshot plugin working in Eclipse and Cordova 2.0 working on android.
Plugin can be found:
https://github.com/josemando/phonegap-plugins/tree/master/Android/Screenshot
I have added:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to my Android manifest xml. And made sure that:
<plugin name="Screenshot" value="org.apache.cordova.Screenshot"/>
is added to my config.xml (that now contains all plugin information from plugin.xml)
Screenshot.js is added to the directory:
assets/www/js/
However I am unsure where exactly to place the Screenshot.java file. The example has it in:
src / org / apache / cordova /
However as I did not have this directory I simply placed it in:
src/uk.co..appname1.appname2/
When I did this however it produced errors, the first one being:
The declared package "org.apache.cordova" does not match the expected package "uk.co.mysitename.appname1.appname2" Screenshot.java /Project Name/src/uk/co/mysitename/appname1/appname2line 8 Java Problem
This refers to this line in the Screenshot.js:
package org.apache.cordova;
The two suggested actions to fix this are to:
Move 'Screenshot.java' to package 'org.apache.cordova' (this directory doesn't exsist atm)
Or change package directory to 'uk.co.mysitename.appname1.appname2'
The second error says:
The method run() of type new Runnable(){} must override a superclass method
The suggested action for this being to "remove '#override' annotation"
I have tried to do every possible combination of these however I cannot seem to make progress and get it all to link up. Usually because it thinks that CordovaRef isn't referenced. I am unsure if the plugin even works on Cordova 2.0.0. I have some experience with Phonegap/Cordova but only in ios with Xcode and Objective C plugins. I am new to Java, Eclipse and Android. Any help or clarification on any of these matters would be greatly appreciated.
Answer resolved by:
Phonegap Screenshot plugin in Cordova 2.0.0
Answer/solution provided by Simon MacDonald
I'm trying to get some server side stuff going for my GWT project. As a test I tried to add in a com.sun.jmx.snmp.SnmpOid object which isn't supported by GWT run-time into my GreetingServiceImpl.java (a file that gets generated with every GWT project), but it's still saying that it's not supported.
I did the RPC GWT tutorial and when I copied the same code into that projects GreetingServiceImpl it worked fine.
I feel that I'm missing a reference or a line in an XML file. I've compared both projects thoroughly but couldn't find any discrepancies.
Any help would be appreciated.
Exact Error: com.sun.jmx.snmp.SnmpOid is not supported by Google App Engine's Java runtime environment
Please check the source path in your .gwt.xml file. It should say something like:
<source path='client' />
<source path='shared' />
Make sure, that your GreetingServiceImpl isn't in the source path.
If that's not the problem, please provide the exact error message you get.
Update
The error message you provided now, indicates that the class isn't supported by AppEngine - that's not the same as "not supported by GWT". If you don't need AppEngine, remove AppEngine support from your project (Project > Properties > Google > AppEngine > Use App Engine).