Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Unhandled exception when running sample program SystemInfoExample #3

Closed
HBrydon opened this issue Nov 11, 2012 · 9 comments
Closed
Assignees
Labels
Milestone

Comments

@HBrydon
Copy link

HBrydon commented Nov 11, 2012

First, let me thank you for taking the time to do these excellent examples.

I get an exception on my Pi when running SystemInfoExample:

pi@mypi ~/workspace/SystemInfoExample $ sudo java -classpath .:pi4j-core-0.0.3-SNAPSHOT.jar com.pi4j.example.SystemInfoExample

HARDWARE INFO

Serial Number : 00000000xxxxxxxx
CPU Revision : 7
CPU Architecture : 7
CPU Part : 0xb76
MIPS : 697.95
Processor : ARMv6-compatible processor rev 7 (v6l)
Hardware Revision : 0005

Is Hard Float ABI : false

OPERATING SYSTEM INFO

OS Name : Linux
OS Version : 3.2.27+

OS Architecture : arm

JAVA ENVIRONMENT INFO

Java Vendor : Sun Microsystems Inc.
Java Vendor URL : http://java.sun.com/
Java Version : 1.6.0_24
Java VM : OpenJDK Zero VM

Java Runtime : OpenJDK Runtime Environment

NETWORK INFO

Hostname : mypi
IP Addresses : 192.168.20.140
Exception in thread "main" java.lang.RuntimeException: Invalid command: hostname --all-fqdns
at com.pi4j.system.NetworkInfo.executeCommand(NetworkInfo.java:82)
at com.pi4j.system.NetworkInfo.getFQDNs(NetworkInfo.java:103)
at com.pi4j.example.SystemInfoExample.main(SystemInfoExample.java:84)
pi@mypi ~/workspace/SystemInfoExample $

@HBrydon
Copy link
Author

HBrydon commented Nov 12, 2012

Additional info for my RPi:

pi@mypi ~/workspace/SystemInfoExample $ hostname --all-fqdns

pi@mypi ~/workspace/SystemInfoExample $ hostname -a

pi@mypi ~/workspace/SystemInfoExample $ hostname -A

pi@mypi ~/workspace/SystemInfoExample $ hostname -d
pi@mypi ~/workspace/SystemInfoExample $ hostname -f
mypi
pi@mypi ~/workspace/SystemInfoExample $ hostname -i
127.0.1.1
pi@mypi ~/workspace/SystemInfoExample $ hostname -I
192.168.20.140
pi@mypi ~/workspace/SystemInfoExample $ hostname -s
mypi
pi@mypi ~/workspace/SystemInfoExample $ hostname -y
hostname: Local domain name not set
pi@mypi ~/workspace/SystemInfoExample $

@fizou
Copy link

fizou commented Nov 14, 2012

same error "hostname --all-fqdns" returns nothing on my raspberry

@savageautomate
Copy link
Member

I will look into this issue next week. Thank you for the defect report.

@HBrydon
Copy link
Author

HBrydon commented Nov 19, 2012

I've looked into this a bit more including studying the source code. I think the code is a bit eager to throw exceptions in places where it shouldn't. I see that you capture info in the form of key/value pairs, and if either a key or value is absent/invalid or blank, you throw an exception. In the context of program design, you require the caller to do some exception handling, and the implementation as it is now requires that the calling code is more complex than the called code. User code handling a possibly blank return value would have to add try/catch logic and translate an exception back to a blank value. This is a minor design problem.

I would suggest that instead of throwing an exception for missing/invalid or blank key or value, that you instead return a blank string, which is actually closer to (or exactly) what the answer should be.

@savageautomate
Copy link
Member

The new 0.0.4-SNAPSHOT build is available for testing. This build includes changes to allow for empty/null NetworkInfo properties returned by the "hostname" command.

You can download it from the Maven repository here:
https://oss.sonatype.org/content/groups/public/com/pi4j/pi4j-core/0.0.4-SNAPSHOT/

Please report success or any remaining open defects/issues.

@ghost ghost assigned savageautomate Nov 20, 2012
@HBrydon
Copy link
Author

HBrydon commented Nov 21, 2012

I am unfortunately running the Debian wheezy build (2012-08-08-wheezy-armel) which seems to have an older java than what you built for the 0.0.4 snapshot (the 0.0.3 jar file worked fine). I have attempted to bring it up to date with "sudo apt-get update" and "sudo apt-get upgrade" but the error remains. Without all the blah blah I get:

root@mypi:/home/pi/workspace/SystemInfoExample# javac -cp pi4j-core-0.0.4-20121120.062224-1.jar -d . SystemInfoExample.java
warning: pi4j-core-0.0.4-20121120.062224-1.jar(com/pi4j/system/NetworkInfo.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: pi4j-core-0.0.4-20121120.062224-1.jar(com/pi4j/system/SystemInfo.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
2 warnings
root@mypi:/home/pi/workspace/SystemInfoExample#
root@mypi:/home/pi/workspace/SystemInfoExample#

root@mypi:/home/pi/workspace/SystemInfoExample# sudo java -classpath .:pi4j-core-0.0.4-20121120.062224-1.jar com.pi4j.example.SystemInfoExample

HARDWARE INFO

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/pi4j/system/SystemInfo : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at com.pi4j.example.SystemInfoExample.main(SystemInfoExample.java:51)
root@mypi:/home/pi/workspace/SystemInfoExample#

I visually inspected your code changes and the code base seems to be okay but I can't verify with what currently I have on my pi.

[Sent from ice weasel on my pi. :-) ]

@savageautomate
Copy link
Member

On the Debian (armel) distribution, I am running the Oracle JDK 7u6 which is much faster than the OpenJDK.
http://www.savagehomeautomation.com/projects/raspberry-pi-installing-oracle-java-development-kit-jdk-170u.html

@HBrydon
Copy link
Author

HBrydon commented Nov 24, 2012

I have now updated to Oracle JDK 1.7.0_06 and the code works fine (fix verified).

Thanks for all of your hard work!

@savageautomate
Copy link
Member

Thank you for testing it out. Issue closed. Fixed in 0.0.4-SNAPSHOT

savageautomate pushed a commit that referenced this issue Apr 11, 2016
Make I2c polling on the MCP23017 IO expander dynamic
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants