(Working in NetBeans/Java) I use a button to retrieve values from an external source, and everything worked all well and fine with minor issues, then I started encountering a java.lang.OutOfMemoryError: unable to create new native thread
exception
This application writes the external values to a JTable. This external values are public variables in other locations
I know it's bad practice to work with multiple JFrames, but I don't see the point in it to recreate a whole new Java Card or Option Pane/Dialog. I'm also determined to create a work-around to get the thing working.
What could be causing it and how do I fix it?
Here's the code. The exception points to Timer timer = new Timer();
.
String username;
String password;
//...
final Apps.UserManager.NewUser newUser = new Apps.UserManager.NewUser();
newUser.setVisible(true);
newUser.requestFocus();
newUser.suVftrun = 0;
int delay = 10000; // delay for 10 sec.
int period = 1000; // repeat every sec.
do{
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
int bcol1 = model.getColumnCount();
int bcol2 = model.getRowCount();
username = newUser.u2ftrun;
password = newUser.p2ftrun;
System.out.println(newUser.u2ftrun);
System.out.println(newUser.p2ftrun);
try {
String tRecord1 = (String) jTable1.getValueAt(bcol1, bcol2);
if (newUser.suVftrun == 1) {
if (!username.equals(null)) {
if (!tRecord1.equals(username)) {
model.addRow(new Object[]{username, password});
this.cancel();
} else {
System.out.println("Same Data");
}
} else {
System.out.println("No Data Received!");
}
} else {
System.out.println("User hasn't been created yet");
}
} catch (Exception ex) {
System.out.println("No values in table. Trying alternative");
try {
if (newUser.suVftrun == 1) {
if (!username.equals(null)) {
try {
model.addRow(new Object[]{username, password});
this.cancel();
} catch (Exception e) {
System.out.println("Repeating...");
}
} else {
System.out.println("No Data Received!");
}
} else {
System.out.println("User hasn't been created yet");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, delay, period);
} while (newUser.isVisible());