|
源程序点击运行后报错如下
Linking ...js.tinyvm.TinyVMException: Method java.lang.System.exit is an unknown native method. You are probably using JDK APIs or libraries that cannot be run under leJOS.
at js.tinyvm.MethodRecord.<init>(MethodRecord.java:80)
at js.tinyvm.ClassRecord.storeMethods(ClassRecord.java:673)
at js.tinyvm.Binary.processMethods(Binary.java:653)
at js.tinyvm.Binary.createFromClosureOf(Binary.java:313)
at js.tinyvm.TinyVMTool.link(TinyVMTool.java:97)
at js.tinyvm.TinyVMTool.link(TinyVMTool.java:48)
at lejos.pc.tools.NXJLink.start(NXJLink.java:134)
at lejos.pc.tools.NXJLink.run(NXJLink.java:101)
at lejos.pc.tools.NXJLink.start(NXJLink.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at lejos.pc.tools.ToolStarter.startTool(ToolStarter.java:31)
at lejos.pc.tools.NXJLink.main(NXJLink.java:28)
Linking the file failed with exit status 1
他的原程序如下
package de.tud.et.ifa.agtele.nxtbrick.steering;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Motor;
import lejos.nxt.comm.BTConnection;
import lejos.nxt.comm.Bluetooth;
import lejos.robotics.navigation.TachoPilot;
public class NXTSlave {
private final String waiting = "Waiting...";
private final String closing = "Closing...";
private final String receiving = "Receiving ...";
final byte COMMAND_STEER = 0x01;
final byte COMMAND_DISCONNECT = 0x03;
private boolean closeConnectionFlag = false;
private byte recDegree[];
private byte recSpeed[];
private byte data[];
/*
* data format
*
* COMMAND (byte 0) | DEGREE LSB | DEGREE MSB | SPEED LSB | SPEED MSB
*/
DataInputStream dis;
DataOutputStream dos;
BTConnection btc;
private Motor rightMotor = Motor.A;
private Motor leftMotor = Motor.B;
TachoPilot pilot = new TachoPilot(5.5f, 11.5f, leftMotor, rightMotor);
private int maxSpeed = 15;
private static int byteToInt(byte data[]) {
int val = 0;
val = (int) (0xFF & data[0]);
val |= (int) ((0xFF & data[1]) << 8);
return val;
}
public void run() {
while (true) {
waitForConnection();
receiveCommands();
}
}
private void waitForConnection() {
LCD.clear();
LCD.drawString(waiting, 0, 0);
LCD.refresh();
btc = Bluetooth.waitForConnection();
}
private void receiveCommands() {
LCD.clear();
LCD.drawString(receiving, 0, 0);
LCD.refresh();
dis = btc.openDataInputStream();
dos = btc.openDataOutputStream();
int degree = 0;
int speed = 0;
int dataLen = 0;
data = new byte[5];
recSpeed = new byte[2];
closeConnectionFlag = false;
while (!Button.ESCAPE.isPressed() && !closeConnectionFlag) {
try {
dataLen = Bluetooth.btRead(data, 0, 5);
if (dataLen > 0) {
LCD.drawString("num bytes: " + dataLen, 0, 2);
byte command = data[0];
LCD.drawString("Command : " + (int) command, 0, 3);
switch (command) {
case COMMAND_STEER:
if (dataLen == 5) {
recDegree = new byte[2];
recSpeed = new byte[2];
System.arraycopy(data, 1, recDegree, 0, 2);
degree = byteToInt(recDegree);
System.arraycopy(data, 3, recSpeed, 0, 2);
speed = byteToInt(recSpeed);
steer(degree, speed);
}
break;
case COMMAND_DISCONNECT:
LCD.drawString("disconnect", 0, 4);
closeConnectionFlag = true;
break;
default:
LCD.drawString("Unknown Command", 0, 4);
break;
}
}
Thread.sleep(200);
} catch (Exception e) {
}
}
closeConnection();
}
/**
* Maps degree to turnRate. The mapping is realized by a sawtooth function
*
* @param degree
* @return turnRate
*/
private int getTurnRate(int degree) {
float turnRate = 0;
if (degree > 0 && degree < 180) {
turnRate = 200 * degree / 90;
} else if (degree > 180 && degree < 360) {
turnRate = -200 * (degree - 180) / 90;
} else {
turnRate = 0;
}
return (int) turnRate;
}
private void steer(int degree, int speed) {
int directionFactor = 1;
LCD.drawString("deg : " + degree, 0, 4);
LCD.drawString("speed : " + speed, 0, 5);
if (degree > 90 && degree < 270) {
directionFactor = -1;
}
LCD.drawString("turn rate :" + getTurnRate(degree), 0, 6);
if (speed <= 0) {
pilot.stop();
} else {
pilot.setMoveSpeed(maxSpeed * speed / 100);
pilot.steer(getTurnRate(degree), directionFactor * 1080, true);
}
}
private void closeConnection() {
pilot.stop();
LCD.clear();
LCD.drawString(closing, 0, 0);
try {
dis.close();
dos.close();
btc.close();
wait(100);
} catch (Exception e) {
}
}
/**
* @param args
*/
public static void main(String[] args) {
NXTSlave s = new NXTSlave();
s.run();
}
}
应该如何处理这个报错啊,大侠们。小弟做这个程序要交作业实在是十万火急,现在连开头都没开始。
这套程序在现有的leJOS 0.9.1会出现报错,但是在以前的版本leJOS 0.8.5是可以正常运行。通过tomcat或者通过vii-controller实习对小车的运动控制。我的任务是找到API的问题,使得该程序在leJOS 0.9.1可以实现和旧版本一样的功能。但是现在我这个程序用eclipse运行就出现上面的错误。
PS :我用我同学电脑的eclipse将程序烧入NXT,运行NXT出现如下报错:
Exception: 14
at: 177:8
at: 176:45
at: 175:92
at: 174:10
at: 173:8
at: 41:69
at: 49:5
这是我这学期的一个大作业,但是小弟学自动化的没有什么JAVA基础。希望了解Teleautomaten相关知识的前辈们能给我多些指点。我实在是已经没有办法,找不到人解答了。我的助教很忙基本没有时间搭理我,希望各位帮帮我这个苦逼学生。
|
|