Forum Stats

  • 3,852,353 Users
  • 2,264,094 Discussions
  • 7,905,042 Comments

Discussions

Why NumberFormatException thrown at code: DeviceManager.open(7);

md.nawazish.khan-JavaNet
md.nawazish.khan-JavaNet Member Posts: 5
edited Dec 22, 2014 5:55AM in Java ME Embedded

I am trying a very basic GPIO pin access program thru Java ME 8.1 (SDK). For this I am creating a custome device thru Custom Device Editor. The configuration of the custom device is as follows (it has only one GPIO pin):

ID: 7, Name: Pin7, H/W Port Number: 0, H/W Pin Number: 7, Direction: Output, Trigger: None, Output: True(checked), Value: Low, Opened: No, Power: On (Group ID: 1)

Here is my MIDLet class to access the GPIO Pin:

package gpio;

import java.io.IOException;

import javax.microedition.midlet.MIDlet;

import javax.microedition.midlet.MIDletStateChangeException;

import jdk.dio.DeviceManager;

import jdk.dio.DeviceNotFoundException;

import jdk.dio.UnavailableDeviceException;

import jdk.dio.gpio.GPIOPin;

public class GPIOController extends MIDlet {

    GPIOPin pin7;

    public GPIOController() {

        // TODO Auto-generated constructor stub

    }

    @Override

    protected void destroyApp(boolean unconditional)

            throws MIDletStateChangeException {

        try {

            pin7.close();

        } catch (IOException e) {

            System.out.println("IOException");

            e.printStackTrace();

        }

    }

    @Override

    protected void startApp() throws MIDletStateChangeException {

        try {

            pin7 = DeviceManager.open(7);

            pin7.setValue(true);

            Thread.sleep(5000);

            pin7.setValue(false);

            Thread.sleep(2500);

        } catch (DeviceNotFoundException e) {

            System.out.println("DeviceNotFound Yaar!");

            e.printStackTrace();

        } catch (UnavailableDeviceException e) {

            System.out.println("Yaar Device is Unavailable");

            e.printStackTrace();

        } catch (IOException e) {

            System.out.println("IOException raised");

            e.printStackTrace();

        } catch (InterruptedException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (NumberFormatException ne){

            System.out.println("number format exception thrown");

            ne.printStackTrace();

        }

    }

Output Console:

------------------------

number format exception thrown

java.lang.NumberFormatException:

- java/lang/Integer.parseInt(), bci=45

- java/lang/Integer.parseInt(), bci=3

- jdk/dio/DeviceMgmtPermission.implies(), bci=341

- com/oracle/meep/security/PermissionsHash.implies(), bci=57

- com/oracle/meep/security/Permissions.implies(), bci=24

- com/oracle/meep/security/AccessControllerInternal.checkPermission(), bci=28

- java/security/AccessController.checkPermission(), bci=1

- jdk/dio/DeviceManager.open(), bci=169

- jdk/dio/DeviceManager.open(), bci=3

- jdk/dio/DeviceManager.open(), bci=4

- gpio/GPIOController.startApp(GPIOController.java:34)

- javax/microedition/midlet/MIDletTunnelImpl.callStartApp(), bci=1

- com/sun/midp/midlet/MIDletPeer.startApp(), bci=5

- com/sun/midp/midlet/MIDletStateHandler.startSuite(), bci=246

- com/sun/midp/main/AbstractMIDletSuiteLoader.startSuite(), bci=38

- com/sun/midp/main/CldcMIDletSuiteLoader.startSuite(), bci=5

- com/sun/midp/main/AbstractMIDletSuiteLoader.runMIDletSuite(), bci=130

- com/sun/midp/main/AppIsolateMIDletSuiteLoader.main(), bci=26

Device Log

----------------

[18:30:23.784]   INFO - lkit.bootstrap.DeployerManager - Registering custom property editors

[18:30:23.808]   INFO - me.toolkit.bootstrap.Namespace - Starting batch, base module object-server

[18:30:23.827]   INFO - bootstrap.ObjectGraphProcessor - Consolidating dependencies...

[18:30:23.828]   INFO - bootstrap.ObjectGraphProcessor - Consolidated dependencies...

[18:30:23.828]   INFO - bootstrap.ObjectGraphProcessor - Calculating order...

[18:30:23.829]   INFO - bootstrap.ObjectGraphProcessor - Calculated order

[18:30:23.857]   INFO - un.jme.toolkit.bootstrap.Batch - Initializing objects...

[18:30:23.858]   INFO - un.jme.toolkit.bootstrap.Batch - Applying I18N

[18:30:23.858]   INFO - un.jme.toolkit.bootstrap.Batch - Initialized objects

[18:30:23.858]   INFO - un.jme.toolkit.bootstrap.Batch - Calling create() methods...

[18:30:23.859]   INFO - un.jme.toolkit.bootstrap.Batch - Calling start() methods...

[18:30:23.867]   INFO - un.jme.toolkit.bootstrap.Batch - Objects started

[18:30:23.871]   INFO - me.toolkit.bootstrap.Namespace - Starting batch, base module devices/GPIOPin

[18:30:26.899]   INFO - bootstrap.ObjectGraphProcessor - Consolidating dependencies...

[18:30:26.900]   INFO - bootstrap.ObjectGraphProcessor - Consolidated dependencies...

[18:30:26.900]   INFO - bootstrap.ObjectGraphProcessor - Calculating order...

[18:30:26.908]   INFO - bootstrap.ObjectGraphProcessor - Calculated order

[18:30:28.097]   INFO - un.jme.toolkit.bootstrap.Batch - Initializing objects...

[18:30:28.504]   INFO - un.jme.toolkit.bootstrap.Batch - Applying I18N

[18:30:28.505]   INFO - un.jme.toolkit.bootstrap.Batch - Initialized objects

[18:30:28.505]   INFO - un.jme.toolkit.bootstrap.Batch - Calling create() methods...

[18:30:28.659]   INFO - un.jme.toolkit.bootstrap.Batch - Calling start() methods...

[18:30:33.628]   INFO - n.kvem.location.LocationBridge - Location dir contents: [Ljava.io.File;@16612a51

[18:30:33.628]   INFO - n.kvem.location.LocationBridge - LandmarkStore names [email protected]

[18:30:33.628]   INFO - n.kvem.location.LocationBridge - Landmark stores:

[18:30:33.629]   INFO - n.kvem.location.LocationBridge - Get categories from store: null

[18:30:33.635]   INFO - n.kvem.location.LocationBridge - Default LandmarkStore:[email protected]

[18:30:33.635]   INFO - n.kvem.location.LocationBridge - LandmarkStore: [email protected]

[18:30:33.635]   INFO - n.kvem.location.LocationBridge - Concatinated categories:

[18:30:33.816]   INFO - .rmiimpl.RemotingConnectorImpl - Starting JMX connector on service:jmx:rmi:///jndi/rmi://127.0.0.1:60379/device-3

[18:30:53.726]   INFO -                      [email protected] - javanotify_set_vm_args() >>

[18:30:53.727]   INFO -                      [email protected] - javanotify_start() >>

[18:30:53.762]   INFO - toolkit.ui.actions.AmsExecImpl - Proxy connected. isNetworkMonitorSupported = false

[18:30:54.135]   INFO - un.jme.toolkit.bootstrap.Batch - Objects started

Please let me know what wrong am I doing?

Sincerely,

M. Nawazish. Khan

Answers

This discussion has been closed.