This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,592 Users
  • 2,269,776 Discussions


Java SE and OpenJDK Device I/O GPIOLEDSample problem

user11260292 Member Posts: 1
edited Jan 7, 2016 8:37AM in Java ME Embedded


I am toying around with my Raspberry Pi B Rev 2, Java ME, Java SE and Device I/O. I've come a long way, but I stumble upon an inexplicable exception in

To build and install Device I/) on my Raspberry Pi, I follo0wed the instructions given at

The sample program (located in dio-samples.jar) lets an LED blink for a while by "opening" it via two alternative ways:

a) By using an ad-hoc GPIOPinConfig in the method, and

b) By using a device id in the id) method.

By figuring out how to supply the java.policy and file, I managed to run the program to let the LED blink through method (a).

Unfortunately, the program exits with an AccessControl exception as follows:

Exception in thread "main" access denied ("jdk.dio.DeviceMgmtPermission" "*:18" "open")






    at GPIOLEDSample.blinkLEDByDeviceId(

my java.policy section for the samples file is this:

grant codeBase "file:./dio-samples.jar" {

        permission jdk.dio.DeviceMgmtPermission "*:*";

        permission jdk.dio.gpio.GPIOPinPermission "*:*";


and the file is this:

# RPi rev2 P1 header pins

1 = deviceType: gpio.GPIOPin, pinNumber:4, name:GPIO4, predefined:true

2 = deviceType: gpio.GPIOPin, pinNumber:7, name:GPIO7, mode:4, direction:1, predefined:true

3 = deviceType: gpio.GPIOPin, pinNumber:17, name:GPIO17, predefined:true

4 = deviceType: gpio.GPIOPin, pinNumber:18, name:GPIO18, mode:4, direction:1, predefined:true

5 = deviceType: gpio.GPIOPin, pinNumber:22, name:GPIO22, predefined:true

6 = deviceType: gpio.GPIOPin, pinNumber:23, name:GPIO23, mode:4, direction:1, predefined:true

7 = deviceType: gpio.GPIOPin, pinNumber:24, name:GPIO24, mode:4, direction:1, predefined:true

8 = deviceType: gpio.GPIOPin, pinNumber:25, name:GPIO25, mode:4, direction:1, predefined:true

9 = deviceType: gpio.GPIOPin, pinNumber:27, name:GPIO27, predefined:true

300 = deviceType: spibus.SPIDevice, name:SPI0.0, controllerNumber:0, address:0, csActive:1, wordLength:8, clockFrequency:500000, clockMode:1, bitOrdering:1, predefined:true

100 = deviceType: uart.UART, controllerName:ttyAMA0, name:ttyAMA0, baudRate:19200, dataBits:8, parity:0, stopBits:1, flowControl:0, predefined:true

gpio.GPIOPin = initValue:0, controllerNumber:0, direction:0, mode:1, trigger:0, predefined:true

uart.UART = baudRate:19200, parity:0, dataBits:8, stopBits:1, flowControl:0, predefined:true

I have two questions:

(a) Can you explain the access control exception for the id) method call?

(b) Why does the sample code use "18" as a device id, where the file declares the device id for GPIO pin 18 to be "4"? When I run a cross-check programm via Java ME 8.2 with id), I have to use device id 4 to get the same GPIO pin to glink the LED?

(c) When modifying the sample program to use the device id 4, it seem to make no difference, except for the access control exception to refer to "*:4" instead :-(


  • Alexander Mironenko-Oracle
    Alexander Mironenko-Oracle Member Posts: 16
    edited Dec 28, 2015 5:40AM


    Can say only about Java ME.

    a) On Java ME you also need to ask permissions in .jad or in manifest file. If you use Netbeans it is enough to open project properties -> Application Descriptor -> API Permissions. Click Add button, select necessary permissions. In _polixy.txt file for Java it is described only permissions for clients. During the installation, your application is assigned for some client(if it is not signed, client will be untrusted) and ONLY requested permissions intersected with clients permissions will be granted. More detailed information is in MEEP specification: Security for Applications

    b) All GPIO device ids are listed in Getting Started guide:

    Also all Java ME related samples are delivered with Netbeans. New Project -> Samples -> Java ME SDK 8.2

    c) See a), you still need to request permission to have an access to GPIO in Java ME 8.2 on RPi.



  • HarrySatt
    HarrySatt Member Posts: 26
    edited Jan 7, 2016 8:37AM


    Be sure to remove all Midlets from RPi. otherwise the pin is locked already. Have a look in the JAD file by starting the Projects -> Properties in the API Permission and make sure you have set the entries correct.

    1 = deviceType: gpio.GPIOPin, pinNumber:4, name:GPIO4, predefined:true

    this is really confusing. This is an input pin. Trying to use it as output gives you an exception.

    Have a look in

    an you see

    1GPIO4GPIO 4controllerNumber = 0

    pinNumber = 4

    direction = GPIOPinConfig.DIR_INPUT_ONLY

    mode = DeviceConfig.DEFAULT

    trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

    initValue - ignored

    The pin number is not correct. have a look in the picture underneath the list. Look for GPIO4 and you will see that the RPi Pin number is 7

    But using an output the first option is device 2

    2GPIO7GPIO 7controllerNumber = 0

    pinNumber = 7

    direction = GPIOPinConfig.DIR_OUTPUT_ONLY


    trigger = GPIOPinConfig.TRIGGER_BOTH_EDGES

    initValue = false

    PinNumber again is not correct. use RPi PinNumber 26 instead. Use DeviceManager.Open(2) this is the device number.

    the exception you get is with that info easy to make clear.

    Exception in thread "main" access denied ("jdk.dio.DeviceMgmtPermission" "*:18" "open")

    You are trying to open GPIO18:18 but the permission you have to add si java.util.PropertyPermission "microedition.platform" "read"

    4GPIO18GPIO 18controllerNumber = 0

    pinNumber = 18

    direction = GPIOPinConfig.DIR_OUTPUT_ONLY


    trigger - ignored

    initValue = false

    with this it should blink on RPi Pin 12

    regards, harald

This discussion has been closed.