1

I've an Html String:

String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=/"tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";

I want to display the text as well as Image on my LWUIT Form Screen,For my Requirement I've used the below code:

public class LwuitMidlet extends MIDlet {

    public void startApp() {
        Display.init(this);
Form f = new Form("Hello, LWUIT!");
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=www.teluguone.com/tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";

    HTMLComponent com=new HTMLComponent();
       com.setPreferredSize(new Dimension(300,300));

       com.setHTML(html, null, null, false);
       com.setShowImages(true);

       //com.setHTML(image, null, null, false);

      f.addComponent(com);

      f.show();
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}

If i use the above code,I'm able to display only the text,but i'm not able to display the image,I've tested my app on Nokia SDK 2.O and SDK 3.0.5

can any one help me?

String
  • 3,660
  • 10
  • 43
  • 66

3 Answers3

2

You need to have the full HTML code not just a snippet. The HTML, body etc.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • But, my Requirement is to parse the text between the

    some text

    tags like above,if i read the HttpURL and pass the full String to HtmlComponent,then the result will be different....
    – String Nov 07 '12 at 07:31
  • Then why aren't you using the parser API? – Shai Almog Nov 11 '12 at 04:47
  • I've tried to parse the text using different html Parsers ,but those are not working in case of j2me.Can't we able to achieve my Requirement using HtmlComponent?My Actual requirement is ,I have a Html URL and i need grab the text(Paragraph of text)from the url and also i need to display the image related to the description on my screen? – String Nov 11 '12 at 05:24
  • LWUIT/Codename One has a builtin HTML parser as part of the HTML component. Please refer to the javadocs in the XML package. – Shai Almog Nov 11 '12 at 09:50
  • https://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/index.html Same thing exists in LWUIT but I don't have the link for that – Shai Almog Nov 22 '12 at 19:40
0

Your src attribute on the img tag is missing the (") character at the beginning. I have not tried but this can be it.

Gorkem Ercan
  • 3,220
  • 1
  • 18
  • 26
  • Can you just take a look at your side pls...?you can check this further info...here http://stackoverflow.com/questions/12708359/lwuit-uncaught-exception-java-lang-outofmemoryerrorstack-trace-incomplete/12892609#12892609 – String Oct 15 '12 at 11:23
0

Have you try using

 com.setBodyText(html);

instead

 com.setHTML(html, null, null, false);

and. I am using HttpRequestHandler implementation from LWUIT example application (you can get the sample apps: LWUITBrowser), instead of DefaultRequestHandler or null.

HttpRequestHandler handler = new HttpRequestHandler();
HTMLComponent com = new HTMLComponent(handler);

Hope it helps.

mico wendy
  • 46
  • 3