在下面的 Java 代码中,我在一个类中填充 ArrayList,然后在另一个类中使用 ArrayList。但是,数组传输但填充了空值。我已经调试了代码并且 ArrayList 确实被填充了,但它的值没有传输。
头等舱:
public String[] log = new String[100];
public ArrayList llog= new ArrayList();
int arraypos= 0;
public void nativeKeyPressed(NativeKeyEvent e) {
if (e.getKeyCode() == NativeKeyEvent.VK_ESCAPE) {
GlobalScreen.unregisterNativeHook();
}
System.out.println(" " + NativeKeyEvent.getKeyText(e.getKeyCode()).toLowerCase() + " ");
llog.add(NativeKeyEvent.getKeyText(e.getKeyCode()).toString().toLowerCase());
System.out.println("list:" + llog.get(arraypos));
arraypos = arraypos + 1;
}
public ArrayList getStrokes (){
return this.llog;
}
二等:
public void TeslaTimer()
{
int delay = 10000; //1 sec = 1000
int period = 90000; // repeat every sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
GlobalKeyListener keyl = new GlobalKeyListener();
ArrayList keylog=keyl.getStrokes();
//TeslaLogger savetoFile = new TeslaLogger();
//savetoFile.TeslaLogger(keylog);
System.out.println("Ring Ring");
for(int i =0; i < keylog.size(); i++){
System.out.println(keylog.get(i));
}
}
}, delay, period);
}