Java Get / Set方法返回null [英] Java Get/Set method returns null
本文介绍了Java Get / Set方法返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得变量其他类(jframe),但get方法返回null ..但set方法正在运行..
I want to get variable other class(jframe) but get method returns null.. But set method is running..
public class FrameGauges extends javax.swing.JFrame {
Elm32x elma=null;
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FrameBaglanti a = new FrameBaglanti();
elma = a.GetElm();
System.out.println(elma);
}
}
我添加了初始化case。当我运行getElm( ),返回null ...我该怎么办?
I added initialized case.. When I run getElm(), that returns null... What should i do ?
public class FrameBaglanti extends javax.swing.JFrame {
Elm32x elm;
public Elm32x GetElm() {
return elm;
}
public void SetElm(Elm32x elm) {
this.elm = elm;
System.out.println("I got " + elm );
}
public void ElmConnect() throws Exception {
elm=null;
elm = new Elm32x(cboxPort.getSelectedItem().toString());
elm.connect();
elmCon = true;
SetElm(elm);
}
private void ButtonBaglanActionPerformed(java.awt.event.ActionEvent evt) {
if (ButtonBaglan.isSelected()) {
try {
// Init the device
if (elmCon == false) {
ElmConnect();
}
} catch (Exception e) {
System.out.println("Baglanamadi..");
ButtonBaglan.setSelected(false);
}
}else {
elm.disconnect();
}
}
}
推荐答案
您需要初始化Elm32x.so代码的一部分将是
You need to initialize Elm32x.so the part of code will be
public class FrameBaglanti extends javax.swing.JFrame {
Elm32x elm = new Elm32x();
//remaining code
这篇关于Java Get / Set方法返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文