i am parsing html page into webview page in android. for this case ,i was using html parser. so please download the html parser 1.6 jar while executing the code
The error i was facing is :
responseBody cannot be resolved to a variable
can anyone solve this error..
this is my code
layout page
---------------------------------
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
activity page
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.android.pnr;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.protocol.HTTP;
import org.htmlparser.Parser;
import org.htmlparser.filters.TagNameFilter;
import org.htmlparser.util.NodeList;
import android.R.string;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
WebView webview;
List allTables;
Dialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient());
webview .getSettings().setJavaScriptEnabled(true);
webview .getSettings().setDomStorageEnabled(true);
webview.loadUrl("http://www.indianrail.gov.in/pnr_Enq.html");
Parser parser=Parser.createParser(responseBody, HTTP.UTF_8);
NodeList nl = parser.parse(null);
NodeList tables = nl.extractAllNodesThatMatch(new
TagNameFilter("table"),true);
CharSequence error1="FLUSHED PNR / PNR NOT YET GENERATED";
CharSequence error2="Following ERROR was encountered in your Query Processing";
CharSequence error3="Please Try Again";
CharSequence error4="Facility Not Avbl due to Network Connectivity Failure.";
for(int i=0;i<tables.size();i++) {
if(tables.elementAt(i).toPlainTextString().contains(error1)||tables.elementAt(i).toPlainTextString().contains(error2)||tables.elementAt(i).toPlainTextString().contains(error3)||tables.elementAt(i).toPlainTextString().contains(error4)){
dialog.dismiss();
return ;
}
{
List table=new ArrayList();
List rows;
List columns;
NodeList nodes = tables.elementAt(i).getChildren();
NodeList trs = nodes.extractAllNodesThatMatch(new
TagNameFilter("tr"),true);
rows=new ArrayList();
for(int j=0;j<trs.size();j++){
NodeList trnodes = trs.elementAt(j).getChildren();
NodeList tds = trnodes.extractAllNodesThatMatch(new
TagNameFilter("td"),true);
columns=new ArrayList<Object>();
for(int z=0;z<tds.size();z++){
if(tds.elementAt(z).toPlainTextString().contains(error1)||tds.elementAt(z).toPlainTextString().contains(error2)||tds.elementAt(z).toPlainTextString().contains(error3)||tds.elementAt(z).toPlainTextString().contains(error4)){
dialog.dismiss();
return ;
}
else
columns.add(tds.elementAt(z).toPlainTextString().replaceAll(" "," " ));
}
rows.add(columns);
}
table.add(rows);
allTables.add(table);
}
}
}}
thanks in advance
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment