GrovePi Java Problem


#1

When following the instructions trying to run the Test.sh file for the Java Library I get this output:

pi@raspberrypi:~/deviceWISE_University/GrovePi/Software/Java $ ./scripts/compile.sh && ./scripts/Test.sh
./src/com/dexterind/grovepi/Board.java:41: error: unreported exception UnsupportedBusNumberException; must be caught or declared to be thrown
    final I2CBus bus = I2CFactory.getInstance(busId);
                                             ^
1 error

This is a fresh installation of both Raspbian and the GrovePi stuff.

Any questions please do not hesitate to ask.

Thanks in advance,

Josh


#2

Hey Josh,
I am not a Java expert but that does look like a problem with the I2C bus. Can you run i2cdetect -y 1 and post what you get there. You should see something with 04 in there. If not then there is a problem with the GrovePi. Did you try running another sensor with the python examples.

-Karan


#3

Karan,

Yes I do see a 04 when issuing the i2cdetect command.

pi@raspberrypi:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- 04 -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    

The python programs for firmware check and led blink run fine.

I am using a Raspberry Pi V3 B if that makes any difference with the latest version of Jessie.

Thanks again,

Josh


#4

I have tried using a new installation of the Raspbian for Robots distro that Dex Ind has created. Even with the OS completely up to date I still get the same error when trying the Java compile and Test scripts.


#5

Hey noname580, just want to hop in here. First, I just want to make sure you saw the directions for the GrovePi Java library here: https://github.com/DexterInd/GrovePi/tree/master/Software/Java
There are a few installation steps (getting pi4j) that need to be done before you get going.

We will try to coach you through this, but no one on staff are really Java experts, this was a community contributed library. We’ll do our best.

John


#6

Thank you John.

I did make sure that Pi4J was installed beforehand.

If I get a chance today I may dive into the Java library and see what I can come up with.

Also I would like to test it out on a RPi 2 to see if it is hardware or software.

Will keep this post updated with any findings.


#7

I’m having the same issue as Josh above. When I try and run the compile.sh it results in
./src/com/dexterind/grovepi/Board.java:41: error: unreported exception UnsupportedBusNumberException; must be caught or declared to be thrown
final I2CBus bus = I2CFactory.getInstance(busId);

And of course since the compile doesn’t work, the Test.sh fails also with a:

Error: Could not find or load main class Test

Is there a correction in the works, perhaps something allowing the usage of Java libraries through NetBeans?
I currently have a remote Netbeans connection to my Pi with PI4J and it works fine.
The addition of the Grove Pi+ adds a lot of possibilities but not so much if the Java libraries aren’t functioning.

Thanks for your help


#8

Seems that I am still having issues with the Java library. Hopefully it is something simple I am missing. I am install pi4j and all pre-reqs.

Now I get the following output from the terminal when trying to execute either just the complie.sh or compile.sh and Test.sh together like the instructions.

pi@raspberrypi:~/Desktop/GrovePi/Software/Java $ sudo ./scripts/compile.sh && ./scripts/Test.sh 
./src/com/dexterind/grovepi/Grovepi.java:40: error: unreported exception Exception; must be caught or declared to be thrown
      instance = new Grovepi();
                 ^
1 error

Thanks in advance again for any help with this. Thank you!


#9

I have figured out what the problem is. There needs to be a try catch block when initiating the GrovePi instance in the ./Java/src/com/dexterind/grovepi/Grovepi.java file.

Change line 40 from

  public static Grovepi getInstance() {
    if(instance == null) {
      instance = new Grovepi();
    }
    return instance;
  }

To the following

  public static Grovepi getInstance() {
    if(instance == null) {
      try {
			instance = new Grovepi();
		} catch (Exception e) {
			System.out.println("There was an error");
		}
    }
    return instance;
  }

Now I am not a Java programer so there may be a much better way to write a try catch. Also I would have commented on git but not sure how to do that.

Added that bit of code the compile and Test both run without any apparent errors.


#10

Hi @noname580,

Both of your posts make sense and therefore I have created a Pull Request that treats this issue. Thanks for your contribution.

This the PR’s link: https://github.com/DexterInd/GrovePi/pull/374

If you like, you can also try the PR and see if it works correctly now.

Thank you!