Issue
Im trying to parse a div or a table (pretty much the same for me because the table is within the div).
So I checked out that question: Load a div into a webview on Android
But the problem is that the div which Im working with doesnt have an Id. But it has a class.
So its like : <div class='CSSTableGenerator' style='width:820px'>
What can I do to show the div alone on the webview?
Code:
Document doc = null;
try {
doc = Jsoup.connect(url).get();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Elements ele = doc.getElementsByClass("CSSTableGenerator");
String html = ele.toString();
String mime = "text/html";
String encoding = "utf-8";
webView.loadData(html, mime, encoding);
Logcat of the crush:
08-22 13:22:24.304: D/libEGL(24034): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
08-22 13:22:24.722: D/libEGL(24034): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
08-22 13:22:24.777: D/libEGL(24034): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
08-22 13:22:25.230: D/OpenGLRenderer(24034): Enabling debug mode 0
08-22 13:22:35.543: I/dalvikvm(24034): Could not find method org.jsoup.Jsoup.connect, referenced from method com.example.owl.Results.onCreate
08-22 13:22:35.543: W/dalvikvm(24034): VFY: unable to resolve static method 4835: Lorg/jsoup/Jsoup;.connect (Ljava/lang/String;)Lorg/jsoup/Connection;
08-22 13:22:35.543: D/dalvikvm(24034): VFY: replacing opcode 0x71 at 0x0054
08-22 13:22:35.543: I/dalvikvm(24034): Could not find method org.jsoup.nodes.Document.getElementsByClass, referenced from method com.example.owl.Results.onCreate
08-22 13:22:35.543: W/dalvikvm(24034): VFY: unable to resolve virtual method 4836: Lorg/jsoup/nodes/Document;.getElementsByClass (Ljava/lang/String;)Lorg/jsoup/select/Elements;
08-22 13:22:35.543: D/dalvikvm(24034): VFY: replacing opcode 0x6e at 0x005e
08-22 13:22:36.175: W/Bundle(24034): Key name expected String but value was a android.text.SpannableString. The default value <null> was returned.
08-22 13:22:36.414: W/Bundle(24034): Attempt to cast generated internal exception:
08-22 13:22:36.414: W/Bundle(24034): java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String
08-22 13:22:36.414: W/Bundle(24034): at android.os.Bundle.getString(Bundle.java:1069)
08-22 13:22:36.414: W/Bundle(24034): at android.content.Intent.getStringExtra(Intent.java:4350)
08-22 13:22:36.414: W/Bundle(24034): at com.example.owl.Results.onCreate(Results.java:25)
08-22 13:22:36.414: W/Bundle(24034): at android.app.Activity.performCreate(Activity.java:5104)
08-22 13:22:36.414: W/Bundle(24034): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-22 13:22:36.414: W/Bundle(24034): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
08-22 13:22:36.414: W/Bundle(24034): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
08-22 13:22:36.414: W/Bundle(24034): at android.app.ActivityThread.access$600(ActivityThread.java:153)
08-22 13:22:36.414: W/Bundle(24034): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-22 13:22:36.414: W/Bundle(24034): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 13:22:36.414: W/Bundle(24034): at android.os.Looper.loop(Looper.java:137)
08-22 13:22:36.414: W/Bundle(24034): at android.app.ActivityThread.main(ActivityThread.java:5227)
08-22 13:22:36.414: W/Bundle(24034): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 13:22:36.414: W/Bundle(24034): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 13:22:36.414: W/Bundle(24034): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-22 13:22:36.414: W/Bundle(24034): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-22 13:22:36.414: W/Bundle(24034): at dalvik.system.NativeStart.main(Native Method)
08-22 13:22:36.433: D/AndroidRuntime(24034): Shutting down VM
08-22 13:22:36.433: W/dalvikvm(24034): threadid=1: thread exiting with uncaught exception (group=0x413e3930)
08-22 13:22:36.550: E/AndroidRuntime(24034): FATAL EXCEPTION: main
08-22 13:22:36.550: E/AndroidRuntime(24034): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
08-22 13:22:36.550: E/AndroidRuntime(24034): at com.example.owl.Results.onCreate(Results.java:29)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.Activity.performCreate(Activity.java:5104)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.ActivityThread.access$600(ActivityThread.java:153)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.os.Looper.loop(Looper.java:137)
08-22 13:22:36.550: E/AndroidRuntime(24034): at android.app.ActivityThread.main(ActivityThread.java:5227)
08-22 13:22:36.550: E/AndroidRuntime(24034): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 13:22:36.550: E/AndroidRuntime(24034): at java.lang.reflect.Method.invoke(Method.java:511)
08-22 13:22:36.550: E/AndroidRuntime(24034): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-22 13:22:36.550: E/AndroidRuntime(24034): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-22 13:22:36.550: E/AndroidRuntime(24034): at dalvik.system.NativeStart.main(Native Method)
Solution
Elements can have multiple classes (e.g. <div class="header round first">
. This method checks each class, so you can find the above with el.getElementsByClass("header");
.
In your case
Elements ele = doc.getElementsByClass("CSSTableGenerator");
Answered By - Arun C
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.