1

I'm using dynamic table layout, in that there is image, and textview. The data is coming from an XML document. What I want is that in table the layout at runtime, I have to get the parsed image and textview. I am getting the textview correctly but not the image. I used the method LoadImageFromWebOperations for loading the image, but it gets a class cast exception and error like this:

org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$LimitedInputStream

What could be causing the exception?

EDIT code from comment

private Drawable LoadImageFromWebOperations(String friend_image) { 
  try { 
         System.out.println("friend_image "+friend_image); 
         InputStream is = (InputStream) new URL(friend_image).getContent(); 
         Drawable d = Drawable.createFromStream(is, "src name"); 
          return d; 
         } catch (Exception e) { 
            System.out.println("Exc at oadImageFromWebOperations "+e);
           return null;
       } 
 } 
3
  • Some code needed to solve your issue. Commented May 27, 2011 at 10:56
  • private Drawable LoadImageFromWebOperations(String friend_image) { try { System.out.println("friend_image "+friend_image); InputStream is = (InputStream) new URL(friend_image).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; } catch (Exception e) { System.out.println("Exc at LoadImageFromWebOperations "+e); return null; } }and Commented May 27, 2011 at 11:34
  • Loading an image from the internet tutorial: anddev.org/novice-tutorials-f8/… Commented May 27, 2011 at 11:48

2 Answers 2

1

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/ClassCastException.html

Sign up to request clarification or add additional context in comments.

Comments

1

Try this code; it may solve your problem:

   Bitmap bmImg;
   public Bitmap downloadFile(String fileUrl){
      URL myFileUrl =null;          
      try {
           myFileUrl= new URL(fileUrl);
      } catch (MalformedURLException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
      }
      try {
           HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
           conn.setDoInput(true);
           conn.connect();
           int length = conn.getContentLength();
           InputStream is = conn.getInputStream();

           bmImg = BitmapFactory.decodeStream(is);
           //imView.setImageBitmap(bmImg);
           return bmImg;
      } catch (IOException e) {
           // TODO Better error handling
           e.printStackTrace();
           return null;
      }
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.