Hi everyone,
Im using // kuka_Sunrise_Cabinet / lbr_iiwa_14_R820 / KUKA Sunrise.OS V1.9//.
In the Code programmed down i tried to read the axis value of a frame from a XMl file (Java Dom Parser) so the robot move to some point. but when i synchronized and press run i got this error message :
Java.Nullpointerexception at Xml.run(XML.java:35)
line 35 is : lbr_iiwa_14_R820_1.move(ptp(a1, a2, a3, a4, a5, a6, a7));
There is somthing wrong with initilizing of variables a1, a2,a3,.... the program doesnot see the values of these variable so they consider them equal to null.
if some one could help me to know whats the wrong with the cod i will be so greatfull. Thanks in advance.
Code :
Java
import com.kuka.roboticsAPI.applicationModel.RoboticsAPIApplication;
import static com.kuka.roboticsAPI.motionModel.BasicMotions.*;
import com.kuka.roboticsAPI.controllerModel.Controller;
import com.kuka.roboticsAPI.deviceModel.LBR;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
public class XML extends RoboticsAPIApplication {
private Controller kuka_Sunrise_Cabinet_1;
private LBR lbr_iiwa_14_R820_1;
private static String x;
private static Double a1, a2, a3, a4, a5, a6, a7;
public void initilize() {
kuka_Sunrise_Cabinet_1 = getController("KUKA_Sunrise_Cabinet_1");
lbr_iiwa_14_R820_1 = (LBR) getDevice(kuka_Sunrise_Cabinet_1,
"LBR_iiwa_14_R820_1");
}
public void run() {
getLogger().info("Frame name : " + x);
lbr_iiwa_14_R820_1.move(ptp(a1, a2, a3, a4, a5, a6, a7));
}
public void main(String[] args) {
try {
// get instance of the class and use it to parse new file xmlfile
File xmlfile = new File("C:/Users/Acer/Desktop/neues.xml");
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder db = factory.newDocumentBuilder();
Document doc = db.parse(xmlfile);
// Normalize
doc.getDocumentElement().normalize();
// get the frame Element
NodeList nlist = doc.getElementsByTagName("frame");
// cycle through the Elements
for (int i = 0; i < nlist.getLength(); i++) {
Node nnode = nlist.item(i);
if (nnode.getNodeType() == Node.ELEMENT_NODE) {
Element fframe = (Element) nnode;
// get name and axis values from Frame
x = fframe.getAttribute("name");
a1 = Double.parseDouble(fframe.getElementsByTagName("A1")
.item(0).getTextContent());
a2 = Double.parseDouble(fframe.getElementsByTagName("A2")
.item(0).getTextContent());
a3 = Double.parseDouble(fframe.getElementsByTagName("A3")
.item(0).getTextContent());
a4 = Double.parseDouble(fframe.getElementsByTagName("A4")
.item(0).getTextContent());
a5 = Double.parseDouble(fframe.getElementsByTagName("A5")
.item(0).getTextContent());
a6 = Double.parseDouble(fframe.getElementsByTagName("A6")
.item(0).getTextContent());
a7 = Double.parseDouble(fframe.getElementsByTagName("A7")
.item(0).getTextContent());
}
}
} catch (ParserConfigurationException e) {
// TODO Automatisch generierter Erfassungsblock
e.printStackTrace();
} catch (SAXException e) {
// TODO Automatisch generierter Erfassungsblock
e.printStackTrace();
} catch (IOException e) {
// TODO Automatisch generierter Erfassungsblock
e.printStackTrace();
}
XML app = new XML();
app.runApplication();
}
}
Display More
neues.xml file :