Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5839267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:33:41+00:00 2026-05-22T11:33:41+00:00

i have written something like this: package mypackage; import java.io.InputStream; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection;

  • 0

i have written something like this:

package mypackage;

import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen implements FieldChangeListener
{
    private static String HEADER_CONTENTTYPE = "content-type";
    private static String CONTENTTYPE_TEXTHTML = "text/html";
    String content = "";
    private static final int STATE_0 = 0;
    private static final int STATE_1 = 1;
    private static final int STATE_2 = 2;
    private static final int STATE_3 = 3;
    private static final int STATE_4 = 4;
    private static final int STATE_5 = 5;
    private static final char HTML_TAG_OPEN = '<';
    private static final char HTML_TAG_CLOSE = '>';
    private static final char CR = 0x000D;
    private static final char LF = 0x000A;
    private static final char TAB = 0x0009;
    /**
     * Creates a new MyScreen object
     */
    public MyScreen()
    {
        // Set the displayed title of the screen
        setTitle("MyTitle");

        final ButtonField bf = new ButtonField("New");
        FieldChangeListener listener = new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context) //respond
to button events
            {
                if(context != PROGRAMMATIC)
                {
                    if(field==bf)
                    {
                     //System.out.println("==============================");
                        fun1();
                    }
                }
            }   
        };
        RichTextField rtf = new RichTextField("hello");
        bf.setChangeListener(listener);
        add(bf);
    }

    void fun1()
    {
        try
        {
            System.out.println("asd");
            //Dialog.alert("asd");
            String str =
fun_dwn_txt("www.google.co.in");
            Dialog.alert(str);
        }
        catch(Exception e)
        {           Dialog.alert("Sorry");
            System.out.println("asd");

        }
    }

    String fun_dwn_txt(String str_url) throws Exception
    {
        StreamConnection s = null;
        s = (StreamConnection)Connector.open(str_url);
        HttpConnection httpConn = (HttpConnection)s;

        int status = httpConn.getResponseCode();

        if (status == HttpConnection.HTTP_OK)
        {
            // Is this html?
            String contentType = httpConn.getHeaderField(HEADER_CONTENTTYPE);
            boolean htmlContent = (contentType != null &&
contentType.startsWith(CONTENTTYPE_TEXTHTML));

            InputStream input = s.openInputStream();

            byte[] data = new byte[256];
            int len = 0;
            int size = 0;
            StringBuffer raw = new StringBuffer();

            while ( -1 != (len = input.read(data)) )
            {
                // Exit condition for the thread. An IOException is
                // thrown because of the call to  httpConn.close(),
                // causing the thread to terminate.
//              if ( _stop )
//              {
//                  httpConn.close();
//                  s.close();
//                  input.close();
//              }
                raw.append(new String(data, 0, len));
                size += len;
            }

            raw.insert(0, "bytes received]\n");
            raw.insert(0, size);
            raw.insert(0, '[');
            content = raw.toString();

            if ( htmlContent )
            {
                content = prepareData(raw.toString());
            }
            input.close();
        }
        else
        {
            content = "No";
        }
        s.close();
        return content;
    }

    private String prepareData(String text)
    {
        final int text_length = text.length();
        StringBuffer data = new StringBuffer(text_length);
        int state = STATE_0;
        int count = 0;
        int writeIndex = -1;
        char c = (char)0;

        for ( int i = 0; i < text_length; ++i)
        {
            c = text.charAt(i);
            switch ( state )
            {
                case STATE_0:
                    if ( c == HTML_TAG_OPEN )
                    {
                        ++count;
                        state = STATE_1;
                    }
                    else if ( c == ' ' )
                    {
                        data.insert(++writeIndex, c);
                        state = STATE_5;
                    }
                    else if ( !specialChar(c) )
                    {
                        data.insert(++writeIndex, c);
                    }
                    break;

                case STATE_1:
                    if ( c == '!' && text.charAt(i + 1) == '-' &&
text.charAt(i + 2) == '-' )
                    {
                        System.out.println("Entering Comment state");
                        i += 2;
                        state = STATE_3;
                    }
                    else if ( Character.toLowerCase(c) == 'p' )
                    {
                        state = STATE_4;
                    }
                    else if ( c == HTML_TAG_CLOSE )
                    {
                        --count;
                        state = STATE_0;
                    }
                    else
                    {
                        state = STATE_2;
                    }
                    break;

                case STATE_2:
                    if ( c == HTML_TAG_OPEN )
                    {
                        ++count;
                    }
                    else if ( c == HTML_TAG_CLOSE )
                    {
                        if( --count == 0 )
                        {
                            state = STATE_0;
                        }
                    }
                    break;

                case STATE_3:
                    if ( c == '-' && text.charAt(i+1) == '-' &&
text.charAt(i + 2) == HTML_TAG_CLOSE )
                    {
                        --count;
                        i += 2;
                        state = STATE_0;
                        System.out.println("Exiting comment state");
                    }
                    break;

                case STATE_4:
                    if ( c == HTML_TAG_CLOSE )
                    {
                        --count;
                        data.insert(++writeIndex, '\n');
                        state = STATE_0;
                    }
                    else
                    {
                        state = STATE_1;
                    }
                    break;

                case STATE_5:
                    if ( c == HTML_TAG_OPEN )
                    {
                        ++count;
                        state = STATE_1;
                    }
                    else if ( c != ' ' )
                    {
                        state = STATE_0;
                        if ( !specialChar(c) )
                        {
                            data.insert(++writeIndex, c);
                        }
                    }
                    break;
            }
        }

        return data.toString().substring(0, writeIndex + 1);
    }

    private boolean specialChar(char c)
    {
        return c == LF || c == CR || c == TAB;
    }

    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub

    }
}

but on button click nothing is happening.. Even HttpConnection.HTTP_OK is not responding..

am i missing some detail which i have to mention in xml for internet connectivity…

Please suggest something…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:33:42+00:00Added an answer on May 22, 2026 at 11:33 am
    • http://www.google.co.in is not a URL. You need to use http://www.google.co.in or https://www.google.co.in

    • You are not specifying the connection method (BES, BIS-B, WiFi etc.). While this might work, it does not work always. Are you using WLAN? Then use ;interface=wifi suffix in your connection string. BES? Use ;deviceside=false and so on.

    For more details, please see this article. Using Connector API is not easy in BlackBerry. If you have a more recent BlackBerry (Device Software version 5.0+) then it might be easier to use the Network API

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a multithreaded program in java. I have written something like this
I have written something like this pretty easily in C# ( string GetUrl(new {
In CakePHP 2.0 version, I have written something like this in UsersController.php public function
I have written in my code something like this and the strange thing is
I have written something like this in PHP <script type=text/javascript src=jquery.js></script></script> <script type=text/javascript> function
Hi to all, i have written something like this in the xml file <?xml
i have code written something like this. if(!isset($cid)) { echo <script type=\text/javascript\>alert('OOps, Something went
I have written a Servlet something like this public class ServletUtil extends HttpServlet {
I have something like this: Section 1 ... Section 2 ... Section 3 Subsection
I am trying to call a javascript function onclick. I have written something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.