BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   JVM Error 104 uncaught Exception (http://www.blackberryforums.com/developer-forum/150155-jvm-error-104-uncaught-exception.html)

ali1983 09-15-2008 05:55 AM

JVM Error 104 uncaught Exception
 
Hello:-
I am using BlackBerry 8703e Simulator to run my application. I am using default JDE Example of HTTPS. Please and I am getting the
"JVM Error 104 uncaught Exception". And when I click on continue on blackberry screen I get following error
"Ungaught Exception Java.lang.error".
Please tell me what is the problem with this code. I am sending sample code.

HTTPFetch.java
Code:

/**
 * HTTPFetch.java
 * Copyright (C) 2001-2004 Research In Motion Limited. All rights reserved.
 */

package com.rim.samples.docs.httpfetch;

import java.io.IOException;
import java.io.InputStream;

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

import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;

import com.rim.samples.docs.baseapp.BaseApp;

public class HTTPFetch extends BaseApp implements HTTPFetchResource {
    // Constants.
    private static final String SAMPLE_PAGE = "http://localhost/testpage/sample.txt";
    private static final String[] HTTP_PROTOCOL = {"http://", "http:\\"};
   
    // Members.
    private MainScreen _mainScreen;
    private RichTextField _content;
   
    /**
    * Send and receive data over the network on a
    * separate thread from the main thread of your application.
    */
    ConnectionThread _connectionThread = new ConnectionThread();
   
    //statics
    private static ResourceBundle _resources = ResourceBundle.getBundle(
    HTTPFetchResource.BUNDLE_ID, HTTPFetchResource.BUNDLE_NAME);
   
    public static void main(String[] args) {
        HTTPFetch theApp = new HTTPFetch();
        theApp.enterEventDispatcher();
    }
    /**
    * The ConnectionThread class manages the HTTP connection.
    * Fetch operations are not queued, but if a second fetch request
    * is made while a previous request is still active,
    * the second request stalls until the previous request completes.
    */
    private class ConnectionThread extends Thread {
        private static final int TIMEOUT = 500; //ms
       
        private String _theUrl;
       
        /* The volatile keyword indicates that because the data is shared,
        * the value of each variable must always be read and written from memory,
        * instead of cached by the VM. This technique is equivalent to wrapping
        * the shared data in a synchronized block, but produces less overhead.
        */
        private volatile boolean _start = false;
        private volatile boolean _stop = false;
       
        /**
        * Retrieve the URL. The synchronized keyword ensures that only one
        * thread at a time can call this method on a ConnectionThread object.
        */
        public synchronized String getUrl() {
            return _theUrl;
        }
       
        /**
        * Fetch a page. This method is invoked on the connection thread by
        * fetchPage(), which is invoked in the application constructor when
        * the user selects the Fetch menu item.
        */
        public void fetch(String url) {
            _start = true;
            _theUrl = url;
        }
       
        /**
        *  Close the thread. Invoked when the application exits.
        */
        public void stop() {
            _stop = true;
        }
       
        /**
        * Open an input stream and extract data. Invoked when the thread
        * is started.
        */
        public void run() {
            for(;;) {
                // Thread control.
                while( !_start && !_stop) {
                    // No connections are open for fetch requests,
                    // but the thread has not been stopped.
                    try {
                        sleep(TIMEOUT);
                    } catch (InterruptedException e) {
                        System.err.println(e.toString());
                    }
                }
                // Exit condition.
                if ( _stop ) {
                    return;
                }
                /* Ensure that fetch requests are not missed
                * while received data is processed.
                */
                synchronized(this) {
                    // Open the connection and extract the data.
                    StreamConnection s = null;
                    try {
                        s = (StreamConnection)Connector.open(getUrl());
                        InputStream input = s.openInputStream();
                        // Extract data in 256 byte chunks.
                        byte[] data = new byte[256];
                        int len = 0;
                        StringBuffer raw = new StringBuffer();
                        while ( -1 != (len = input.read(data)) ) {
                            raw.append(new String(data, 0, len));
                        }
                        String text = raw.toString();
                       
                        updateContent(text);
                       
                        input.close();
                        s.close();
                    } catch (IOException e) {
                        System.err.println(e.toString());
                        // Display the text on the screen.
                        updateContent(e.toString());
                    }
                    // Reset the start state.
                    _start = false;
                }
            }
        }
    }
    // Constructor.
    public HTTPFetch() {
        _mainScreen = new MainScreen();
        _mainScreen.setTitle(new LabelField(
        _resources.getString(APPLICATION_TITLE), LabelField.ELLIPSIS
        | LabelField.USE_ALL_WIDTH));
        _mainScreen.add(new SeparatorField());
        _content = new RichTextField(
        _resources.getString(HTTPDEMO_CONTENT_DEFAULT));
        _mainScreen.add(_content);
        _mainScreen.addKeyListener(this);
        _mainScreen.addTrackwheelListener(this);
       
        // Start the helper thread.
        _connectionThread.start();
        pushScreen(_mainScreen);
        fetchPage(SAMPLE_PAGE);
    }
   
    // Retrieve web content.
    private void fetchPage(String url) {
        // Perform basic validation (set characters to lowercase and add http:// or https://).
        String lcase = url.toLowerCase();
        boolean validHeader = false;
        int i = 0;
        for (i = HTTP_PROTOCOL.length - 1; i >= 0; --i) {
            if ( -1 != lcase.indexOf(HTTP_PROTOCOL[i]) ) {
                validHeader = true;
                break;
            }
        }
        if ( !validHeader ) {
            // Prepend the protocol specifier if it is missing.
            url = HTTP_PROTOCOL[0] + url;
        }
       
        // Create a new thread for connection operations.
        _connectionThread.fetch(url);
    }
    // Display the content.
    private void updateContent(final String text) {
        /* This technique creates several short-lived objects but avoids
        * the threading issues involved in creating a static Runnable and
        * setting the text.
        */
        UiApplication.getUiApplication().invokeLater(new Runnable() {
            public void run() {
                _content.setText(text);
            }
        });
    }
    // Close the connection thread when the user closes the application.
    protected void onExit() {
        _connectionThread.stop();
    }
}

HTTPFetchResource.java(Interface)
Code:

package com.rim.samples.docs.httpfetch;

public interface HTTPFetchResource {
    // Hash of: "com.rim.samples.docs.httpfetch.HTTPFetch".
    long BUNDLE_ID = 0xd0dff0654b2ce75fL;
    String BUNDLE_NAME = "com.rim.samples.docs.httpfetch.HTTPFetch";

    int HTTPDEMO_ALERT_REQUESTINPROGRESS = 0;
    int APPLICATION_TITLE = 1;
    int HTTPDEMO_CONTENT_DEFAULT = 2;
}


BaseApp.java
Code:

/*
 * BaseApp.java
 * Copyright (C) 2001-2004 Research In Motion Limited. All rights reserved.
 */

package com.rim.samples.docs.baseapp;

import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.system.Characters;
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.system.TrackwheelListener;
import net.rim.device.api.ui.ContextMenu;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Menu;

public abstract class BaseApp extends UiApplication implements BaseAppResource, KeyListener, TrackwheelListener {
    private MenuItem _closeItem;
    private static ResourceBundle _resources =
    ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
    /* Constructor for the abstract base class. */
    public BaseApp() {
        _closeItem = new MenuItem(_resources, MENUITEM_CLOSE, 200000, 10) {
            public void run() {
                onExit();
                System.exit(0);
            }
        };
    }
    /* Override this method to add custom menu items. */
    protected void makeMenu( Menu menu, int instance) {
        Field focus = UiApplication.getUiApplication().
        getActiveScreen().getLeafFieldWithFocus();
        if(focus != null) {
            ContextMenu contextMenu = focus.getContextMenu();
            if( !contextMenu.isEmpty()) {
                menu.add(contextMenu);
                menu.addSeparator();
            }
        }
        menu.add(_closeItem);
    }
    /* Invoked when the trackwheel is clicked. */
    public boolean trackwheelClick( int status, int time ) {
        Menu menu = new Menu();
        makeMenu( menu, 0);
        menu.show();
        return true;
    }
    /* Invoked when the trackwheel is released. */
    public boolean trackwheelUnclick( int status, int time ) {
        return false;
    }
    /* Invoked when the trackwheel is rolled. */
    public boolean trackwheelRoll(int amount, int status, int time) {
        return false;
    }
    public boolean keyChar(char key, int status, int time) {
        /* Intercept the ESC key and exit the application. */
        boolean retval = false;
        switch (key) {
            case Characters.ESCAPE:
            onExit();
            System.exit(0);
            retval = true;
            break;
        }
        return retval;
    }
    /* Implementation of KeyListener.keyDown(). */
    public boolean keyDown(int keycode, int time) {
        return false;
    }
    /* Implementation of KeyListener.keyRepeat(). */
    public boolean keyRepeat(int keycode, int time) {
        return false;
    }
    /* Implementation of KeyListener.keyStatus(). */
    public boolean keyStatus(int keycode, int time) {
        return false;
    }
    /* Implementation of KeyListener.keyUp(). */
    public boolean keyUp(int keycode, int time) {
        return false;
    }
    protected abstract void onExit();
}

BaseAppResource.java(Interface)
Code:

package com.rim.samples.docs.baseapp;

public interface BaseAppResource {
    // Hash of: "com.rim.samples.docs.baseapp.BaseApp".
    long BUNDLE_ID = 0xb2bbab4764b0c17eL;
    String BUNDLE_NAME = "com.rim.samples.docs.baseapp.BaseApp";

    int MENUITEM_CLOSE = 0;
}

I am using BlackBerry Plugin for Eclipse. And using 8703e as my simulator.

Bye
Muhammad Ali
[email address]

Ivanov 09-15-2008 06:49 AM

Try to locate the line throwing the exception by stepping throug the calls.

ali1983 09-16-2008 12:16 AM

JVM Error 104 uncaught Exception
 
Thanks for the reply. But the problem is that I have done it so. But befire reaching the main method it throws the exception.

Now how u can make calls out of any method.

Bye

Ivanov 09-16-2008 02:43 AM

Are you sure that it's your application that is throwing that exception? It would not make sense since your main() and so your application is not started at all...

stepanz 09-17-2008 04:24 PM

Hi,

I have the same issue. I have 8310 Blackberry and my application is very simple. I am calling a web service and application works fine if I run it in mobile phone emulator (NetBeans IDE 6.1 and Sun Java(TM) Wireless Toolkit 2.5.2 for CLDC) but if I run the application in Blackberry emulator (BlackBerry JDE 4.5) I am getting error message 'JVM Error 104 Uncought: JAXRPCException'. I deployed the application on real device and if I try to run it I am getting error message 'Class java.rmi.RemoteException not found'. What did I do wrong?

Thanks,
Zoran


All times are GMT -5. The time now is 12:52 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.