Note that there are some explanatory texts on larger screens.

plurals
  1. POFetching Data From Web Server using Sax Parsing
    primarykey
    data
    text
    <h2>I am fetching data from Web server using SAX parsing method all the data is shown in LogCat but not shown in my emulator</h2> <pre><code>@SuppressLint("NewApi") public class IotdHandler extends DefaultHandler { private String url = "http://www.nasa.gov/rss/dyn/image_of_the_day.rss"; private boolean inUrl = false; private boolean inTitle = false; private boolean inDescription = false; private boolean inItem = false; private boolean inDate = false; private static Bitmap image = null; private String imageUrl=null; private static String title = null; private static StringBuffer description = new StringBuffer(); private static String date = null; public void processFeed() { try { //This part is added to allow the network connection on a main GUI thread... StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(this); URL urlObj = new URL(url); InputStream inputStream = urlObj.openConnection().getInputStream(); reader.parse(new InputSource(inputStream)); } catch (Exception e) { e.printStackTrace(); System.out.println(new String("Got Exception General")); } } private Bitmap getBitmap(String url) { try { System.out.println(url); HttpURLConnection connection = (HttpURLConnection)new URL(url).openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(input); input.close(); return bitmap; } catch (IOException ioe) { System.out.println(new String("IOException in reading Image")); return null; } catch (Exception ioe) { System.out.println(new String("IOException GENERAL")); return null; } } public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (localName.equals("enclosure")) { System.out.println(new String("characters Image")); imageUrl = attributes.putValue("","url"); System.out.println(imageUrl); inUrl = true; } else { inUrl = false; } if (localName.startsWith("item")) { inItem = true; } else if (inItem) { if (localName.equals("title")) { inTitle = true; } else { inTitle = false; } if (localName.equals("description")) { inDescription = true; } else { inDescription = false; } if (localName.equals("pubDate")) { inDate = true; } else { inDate = false; } } } public void characters(char ch[], int start, int length) { System.out.println(new String("characters")); String chars = new String(ch).substring(start, start + length); System.out.println(chars); if (inUrl &amp;&amp; image == null) { System.out.println(new String("IMAGE")); System.out.println(imageUrl); image = getBitmap(imageUrl); } if (inTitle &amp;&amp; title == null) { System.out.println(new String("TITLE")); title = chars; } if (inDescription) { description.append(chars); } if (inDate &amp;&amp; date == null) { date = chars; } } public static Bitmap getImage() { return image; } public static String getTitle() { return title; } public static StringBuffer getDescription() { return description; } public static String getDate() { return date; } } </code></pre> <hr> <p>This is my MainActivity class I am trying to fetch the data from nasa rss feed all the data is shown in the logcat but not displayed in the emulator</p> <pre><code>public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); IotdHandler handler = new IotdHandler(); //create handler handler.processFeed(); //start parsing resetDisplay(IotdHandler.getTitle(), IotdHandler.getDate(), IotdHandler.getImage(), IotdHandler.getDescription()); } private void resetDisplay(String title, String date, Bitmap image, StringBuffer description) { TextView titleView = (TextView)findViewById(R.id.imageTitle); titleView.setText(title); TextView dateView = (TextView)findViewById(R.id.imageDate); dateView.setText(date); ImageView imageView = (ImageView)findViewById(R.id.imageDisplay); imageView.setImageBitmap(image); TextView descriptionView = (TextView)findViewById(R.id.imageDescription); descriptionView.setText(description); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload