Hi, I am just a begginer at pi and I'm trying to do my first program with netbans for pi, but I am having a trouble, when I run the program, it crashes at "Accessing GPIO..." I'd be greatful if someone helpe me. The code is below
import javax.microedition.midlet.MIDlet;
import jdk.dio.DeviceManager;
import jdk.dio.UnavailableDeviceException;
import jdk.dio.gpio.GPIOPin;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author AugustoRigobertoMore
*/
public class HelloWorld extends MIDlet {
@Override
public void startApp() {
try {
System.out.println("Accessing GPIO...");
GPIOPin pin = (GPIOPin)DeviceManager.open(14);
System.out.println("Blinking...");
System.out.println("HIGH");
pin.setValue(true);
Thread.sleep(3000);
System.out.println("FALSE");
pin.setValue(false);
Thread.sleep(3000);
System.out.println("HIGH");
pin.setValue(true);
System.out.println("FALSE");
Thread.sleep(3000);
pin.setValue(false);
System.out.println("Done...");
pin.close();
} catch (UnavailableDeviceException ex){
Logger.getLogger(HelloWorld.class.getName()).log(
Level.SEVERE, null, ex);
} catch (InterruptedException ex){
Logger.getLogger(HelloWorld.class.getName()).log(
Level.SEVERE, null, ex);
} catch (IOException ex){
Logger.getLogger(HelloWorld.class.getName()).log(
Level.SEVERE, null, ex);
}
}
@Override
public void destroyApp(boolean unconditional) {
}
}
Re: First Java program for pi on rasperry pi with netbeans
Probably due to security, you have to allow your application access to the GPIO pins. At the moment I don't have the details to do this. This is certainly the case when using Java ME, you have to allow access outside of the sandpit.
- DougieLawson
- Posts: 40523
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: First Java program for pi on rasperry pi with netbeans
You'll need to run it with sudo java -cp classpathstuffhere -jar jarfilenamehere
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.