Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
suman2009
Posts: 11
Registered: ‎08-18-2010
My Device: Not Specified

Re: Display HTML in a Screen Field

Hi i am using the same code that u have mentioned.  and i have passed the mainscreen obj and some html data to the BrowserFieldDemo class.but i am not getting the output.

                while debugging the field is generated and added to the mainscreen obj and after that i am getting the exception at the

     browserContent.finishLoading();

     line in BrowserFiledDemo class like

/******************************************/

Exception : java.lang.NullPointerException
No stack trace

/******************************************/

plz give me the solution.

 

 

Thanks in Advance

A.suman

Please use plain text.
Developer
BB-Dude
Posts: 516
Registered: ‎07-23-2010
My Device: 9900

Re: Display HTML in a Screen Field

I do not think anyone can give you a solution to a NullPointerException. You have to find out what is causing that exception by debugging your code.

Please use plain text.
Developer
shahumang8
Posts: 580
Registered: ‎08-09-2010
My Device: Not Specified

Re: Display HTML in a Screen Field

Hello

i try this code but they are not working so help me some urgent 

 

 

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ActiveRichTextField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

public class BrowserField extends MainScreen
{
        
        private MainScreen mainScreen;  
        public BrowserField()
        {
         LabelField title = new LabelField("Hello World Demo" , LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
         setTitle(title);
         add(new RichTextField("Hello World!" ,Field.NON_FOCUSABLE));
         add(new ActiveRichTextField("<p>abcd</p><p>amber&apos; work is moving ahead</p>"));
         String test = "<html><body>Hi how are you???</body></html>";
        mainScreen = new MainScreen(); 
         try
         {  
        	 MBrowserFieldDemo mi=new  MBrowserFieldDemo(test, mainScreen);  //passing the html string and a Mainscreen
             UiApplication.getUiApplication().pushScreen(mainScreen);
         }catch (Exception e)
         {
                        System.out.println("Exception rendering "+e.getMessage());
                }
                
                
        }
       
 }

 

 

Here this is the BrowserField Screen.

 

The second screen is 

 

 

import java.io.IOException;

import javax.microedition.io.HttpConnection;


import net.rim.device.api.browser.field.BrowserContent;
import net.rim.device.api.browser.field.Event;
import net.rim.device.api.browser.field.RedirectEvent;
import net.rim.device.api.browser.field.RenderingApplication;
import net.rim.device.api.browser.field.RenderingException;
import net.rim.device.api.browser.field.RenderingOptions;
import net.rim.device.api.browser.field.RenderingSession;
import net.rim.device.api.browser.field.RequestedResource;
import net.rim.device.api.io.http.HttpHeaders;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.container.MainScreen;

public class MBrowserFieldDemo implements RenderingApplication {
    private String data;
    private static final String REFERER = "referer";
    private RenderingSession renderingSession;
    private HttpConnection currentConnection;
    private Field displayableField;
    private MainScreen mainScreen;

    public MBrowserFieldDemo(String data, MainScreen mainScreen) {
        this.data = data;
        
       // mainScreen = new MainScreen();
     //   pushScreen(mainScreen);
        
        
        
     //   this.mainScreen = mainScreen;
      
        this.mainScreen = new MainScreen();
      
        renderingSession = RenderingSession.getNewInstance();
        // enable javascript
        renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true);
        ResourceFetchThread thread = new ResourceFetchThread(data, null, this);
        thread.start();
    }

    public void processConnection(HttpConnection connection, Event e) {

        // cancel previous request
        if (currentConnection != null) {
            try {
                currentConnection.close();
            } catch (IOException e1) {
            }
        }

        currentConnection = connection;

        BrowserContent browserContent = null;

        try {
            browserContent = renderingSession.getBrowserContent(connection, this, e);

            if (browserContent != null) {
                Field field = browserContent.getDisplayableContent();
                if (field != null) {
                    synchronized (Application.getEventLock()) {
                        this.mainScreen.add(field);
                    }
                }

                browserContent.finishLoading();
                System.out.println("Done loading>>>>>");
            }

        } catch (RenderingException re) {
            System.out.println("RenderingException : " + re);
        } catch (Exception ex) {
            System.out.println("Exception : " + ex);
            ex.printStackTrace();
        }

    }

    public Object eventOccurred(Event event) {

        int eventId = event.getUID();

        switch (eventId) {

            case Event.EVENT_URL_REQUESTED: {
                ResourceFetchThread thread = new ResourceFetchThread(data, null, this);
                thread.start();
                break;
            }
            case Event.EVENT_BROWSER_CONTENT_CHANGED: {
                break;
            }
            case Event.EVENT_REDIRECT: {

                RedirectEvent e = (RedirectEvent) event;
                String referrer = e.getSourceURL();

                switch (e.getType()) {

                    case RedirectEvent.TYPE_SINGLE_FRAME_REDIRECT:
                        // show redirect message
                        Application.getApplication().invokeAndWait(new Runnable() {
                            public void run() {
                                Status.show("You are being redirected to a different page...");
                            }
                        });

                        break;

             /*       case RedirectEvent.TYPE_JAVASCRIPT&colon;
                        break;
                    case RedirectEvent.TYPE_META:
                        // MSIE and Mozilla don't send a Referer for META Refresh.
                        referrer = null;
                        break;
                    case RedirectEvent.TYPE_300_REDIRECT:
                        // MSIE, Mozilla, and Opera all send the original
                        // request's Referer as the Referer for the new
                        // request.
                        Object eventSource = e.getSource();
                        if (eventSource instanceof HttpConnection) {
                            referrer = ((HttpConnection) eventSource).getRequestProperty(REFERER);
                        }
                        break;*/

                }

                HttpHeaders requestHeaders = new HttpHeaders();
                requestHeaders.setProperty(REFERER, referrer);
                ResourceFetchThread thread = new ResourceFetchThread(this.data, event, this);
                thread.start();
                break;

            }
            case Event.EVENT_CLOSE:
                // TODO: close the appication
                break;

            case Event.EVENT_SET_HEADER:        // no cache support
            case Event.EVENT_SET_HTTP_COOKIE:   // no cookie support
            case Event.EVENT_HISTORY:           // no history support
            case Event.EVENT_EXECUTING_SCRIPT:  // no progress bar is supported
            case Event.EVENT_FULL_WINDOW:       // no full window support
            case Event.EVENT_STOP:              // no stop loading support
            default:
        }

        return null;
    }

    /**
     * @see
     */
    public int getAvailableHeight(BrowserContent browserField) {
        // field has full screen
        return Graphics.getScreenHeight();
    }

    /**
     * @see
     */
    public int getAvailableWidth(BrowserContent browserField) {
        // field has full screen
        return Graphics.getScreenWidth();
    }

    /**
     * @see
     */
    public int getHistoryPosition(BrowserContent browserField) {
        // no history support
        return 0;
    }


    public String getHTTPCookie(String url) {
        // no cookie support
        return null;
    }


    public HttpConnection getResource(RequestedResource resource, BrowserContent referrer) {

        if (resource == null) {
            return null;
        }

        // check if this is cache-only request
        if (resource.isCacheOnly()) {
            // no cache support
            return null;
        }

        String url = resource.getUrl();

        if (url == null) {
            return null;
        }

        // if referrer is null we must return the connection
        if (referrer == null) {
//            HttpConnection connection = Utilities.makeConnection(resource.getUrl(), resource.getRequestHeaders(), null);
            HttpConnection connection = new HttpConnectionImpl(url);
            return connection;

        } /*else {

            // if referrer is provided we can set up the connection on a separate thread
            SecondaryResourceFetchThread.enqueue(resource, referrer);

        }*/

        return null;
    }

    /**
     * @see
     */
    public void invokeRunnable(Runnable runnable) {
        (new Thread(runnable)).run();
    }

    public Field getDisplayableField() {
        if (displayableField == null)
            displayableField = new NullField();
        return displayableField;
    }
}


class ResourceFetchThread extends Thread {

    private MBrowserFieldDemo application;
    private Event event;
    private String data;

    ResourceFetchThread(String data, Event event, MBrowserFieldDemo application) {
        this.data = data;
        this.application = application;
        this.event = event;
    }

    public void run() {
        HttpConnection connection = new HttpConnectionImpl(this.data);
        this.application.processConnection(connection, this.event);
    }
}

 

this type i put but there are no output here only show label and richText there no show the html string so help me.

 

Please use plain text.
Visitor
chaitanyamn
Posts: 1
Registered: ‎11-19-2010
My Device: Not Specified

Re: Display HTML in a Screen Field

The above solution is not working in OS 6. I get a white screen. Can some one help ?

 

 

Please use plain text.
Developer
ushernut
Posts: 55
Registered: ‎09-09-2008
My Device: Not Specified

Re: Display HTML in a Screen Field

I had same issue with you.

 

I have implemented them as mentioned above, it works fine before OS 6.0, but on OS 6.0, in the finishLoading(), it hangs there.....

 

I have tried to use BrowserField 2, but it has a problem, we cannot save its content, once the screen is pop out from stack, if we push this screen again, browserfield will not display content any more. BrowserContent doesn't have this issue tho.

 

 

Please use plain text.
New Contributor
tolgakaralar
Posts: 3
Registered: ‎02-21-2011
My Device: Not Specified

Re: Display HTML in a Screen Field

Yes, I had a same problem too. But I can't solve this problem. Can anybody help me ? 

thanks

Please use plain text.
Trusted Contributor
kaibaseto
Posts: 121
Registered: ‎01-19-2011
My Device: Not Specified
My Carrier: engineer

Re: Display HTML in a Screen Field

 

actually the error it`s because in code this fail
renderingSession.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.JAVASCRIPT_ENABLED, true);
somebody knows a correct way ti enable javascript???

 

Please use plain text.
Contributor
ragrik
Posts: 15
Registered: ‎06-01-2011
My Device: 9800
My Carrier: AT&T

Re: Display HTML in a Screen Field

I'm also facing the same problem in blackberry 6.0. Any one can help to solve this issue?

Please use plain text.
New Contributor
ujjwalbsoni20032003
Posts: 4
Registered: ‎10-20-2011
My Device: Blackberry 8700
My Carrier: vodafone

Re: Display HTML in a Screen Field

I get an error when i call a page with URL Parameters like ::

 

PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread("http://mysite.com?q=RenderingSession.getNewInstance().getBrowserContent(&ie=utf-8&oe=utf-8&aq=t&rls=...:smileysurprised:", null, null, null, this);

 

When i debug the code, it shows me source not found in  conn = (HttpConnection) Connector.open(url);           

 

I will have to implement this on blackberry model 8700 JDE 4.5.

 

Thanks,

 

Ujjwal Soni

 

Please use plain text.
Contributor
dhara_jogi
Posts: 16
Registered: ‎04-25-2013
My Device: None
My Carrier: None

Re: Display HTML in a Screen Field

tek3 could please let me know where have you added the snippet code:-

 

ByteArrayOutputStream output = new ByteArrayOutputStream();
Base64OutputStream boutput = new Base64OutputStream( output );
output.write( "data&colon;text/html;base64,".getBytes() );
boutput.write( HTML_STRING.getBytes() ); // HTML_STRING is the string containing your HTML content
boutput.flush();
boutput.close();
output.flush();
output.close();

in which class, im trying to add it in the Mainscreen of my application before calling the PrimaryResourceFetchThread to start.

Thanks & Regards
Dhara Jogi
Please use plain text.