EV3 via Bluetooth, NullPointer

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

EV3 via Bluetooth, NullPointer

Postby WindWalker » Tue Apr 08, 2014 3:54 pm

Hi all
Just want start by thanking you all for making LejOS.

I have a small problem with the program i am writing atm.
I am building a robot to be controlled by a PC over a Bluetooth connection.
I can control the Sound and Display fine. But when i try to operate a remote motor i get a Null Pointer Exception.

i am running LejOS 0.8.0 (master from git)
32 bit eclipse and java (on a 64bit PC)

I really hope someone can help me, i have tryed everything i can think off on my own and with google help.

This is my control class
I hear the beep fine and the display gets cleared.
Code: Select all
package robot;

import java.rmi.RemoteException;
import lejos.hardware.BrickFinder;
import lejos.hardware.BrickInfo;
import lejos.hardware.Sound;
import lejos.hardware.lcd.GraphicsLCD;
import lejos.remote.ev3.RMIRegulatedMotor;
import lejos.remote.ev3.RemoteEV3;
import lejos.utility.Delay;

public class Control {
   
   RemoteEV3 ev3 = null;
   RMIRegulatedMotor motorA = null;
   RMIRegulatedMotor motorB = null;
   RMIRegulatedMotor motorC = null;
   RMIRegulatedMotor motorD = null;
   
   //FrontDorOpen
   private boolean isOpen = false;   
   public boolean getIsOpen() { return isOpen; }
   
   public Control(){
      setup();
   }
   
   private void setup() {
      try {
         BrickInfo[] bricks = BrickFinder.discover();
         for(BrickInfo info: bricks) {
            System.out.println("Ev3 found on Bluetooth ip: " + info.getIPAddress());
         }
         
         ev3 = new RemoteEV3(bricks[0].getIPAddress());
         
      } catch (Exception e) {
         e.printStackTrace();
      }
      
      ev3.setDefault();
      GraphicsLCD display = ev3.getGraphicsLCD();
      display.clear();
      Sound.beep();
      
      motorA = ev3.createRegulatedMotor("A",'l');
      motorB = ev3.createRegulatedMotor("B",'l');
      motorC = ev3.createRegulatedMotor("C",'l');
      motorD = ev3.createRegulatedMotor("D",'l');
   
      Sound.beep();
      try {         
                        // test the first moter
         motorA.rotate(360);
      } catch (RemoteException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();         
      }      
   }
   public boolean forward(int sek) throws RemoteException{
      motorA.forward();
      motorB.forward();
      Delay.msDelay(sek*1000);
      motorA.stop(false);
      motorB.stop(false);
      return false;
   }

}


the error i get from eclipse:
Code: Select all
Exception in thread "main" java.lang.NullPointerException
   at lejos.remote.ev3.RMIRemoteRegulatedMotor.getLimitAngle(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:606)
   at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
   at sun.rmi.transport.Transport$1.run(Transport.java:177)
   at sun.rmi.transport.Transport$1.run(Transport.java:174)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
   at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
   at java.lang.Thread.run(Thread.java:744)
   at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
   at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
   at sun.rmi.server.UnicastRef.invoke(Unknown Source)
   at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
   at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
   at com.sun.proxy.$Proxy4.getLimitAngle(Unknown Source)
   at robot.Control.setup(Control.java:62)
   at robot.Control.<init>(Control.java:27)
   at robot.RemoteControleFromPc.main(RemoteControleFromPc.java:10)
WindWalker
New User
 
Posts: 2
Joined: Tue Apr 08, 2014 3:29 pm

Re: EV3 via Bluetooth, NullPointer

Postby lawrie » Tue Apr 08, 2014 7:03 pm

The second parameter to createRegulatedMotor should be N (for NXT), L (for large), M (for medium) or G (for glide wheel). It must be upper case. This is probably causing the exception.

There is probably a better way to specify the motor type, and the class needs more error checking, and more specific exceptions.
lawrie
leJOS Team Member
 
Posts: 921
Joined: Mon Feb 05, 2007 1:27 pm

Re: EV3 via Bluetooth, NullPointer

Postby WindWalker » Wed Apr 09, 2014 2:48 pm

THANKS! workes perfeckly now!

edit: yes the sanity and exception check's are comming ;)
WindWalker
New User
 
Posts: 2
Joined: Tue Apr 08, 2014 3:29 pm


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff