-
Multiple classes error
Hi,
I have a class made to vote on a form i have on my website and the code works as is. I am trying to break the methods down into different classes so that i can work on the code easier. When i run the new class that calls methods from other classes i get a "Exception in thread "main" java.lang.NullPointerException" error in the console. The error occurs whenever i try up update a JLabel in any of my new classes. here is how my current project is set up with the first set of bullets being the packages:
- back_end
- randomuser.java
- timer_functions.java
- tor_connect.java
- variables.java
- vote.java
- bot
- GUI_components
And here is the code for the main class (start_gui_bot.java):
Code:
package bot;
import javax.swing.JFrame;
import javax.swing.JPanel;
import back_end.timer_functions;
import back_end.tor_connect;
import back_end.variables;
import back_end.vote;
import GUI_components.label_set;
public class start_gui_bot extends JFrame{
variables call_vars = new variables();
public start_gui_bot (String url) throws Exception {
variables.bUrl = url;
call_vars.timeRemaining = variables.timertime;
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(480, 250);
call_vars.panel = new JPanel();
call_vars.panel.setLayout(null);
}
public static void main(String[] args) throws Exception {
start_gui_bot vb = new start_gui_bot (variables.form_url);
variables call_vars = new variables();
label_set ls = new label_set();
tor_connect tc = new tor_connect();
vote cv = new vote();
timer_functions tf = new timer_functions();
ls.add_labels();
if ( variables.set_tor == "true" ) {
tc.setTor();
}
for (int i = 1; i <= variables.make_vote_number; i++){
cv.vote ();
tf.start();
tf.stop();
tf.reset();
}
call_vars.label.setText("Done!");
}
}
the error is thrown at ls.add_labels(); so here is its code:
Code:
package GUI_components;
import javax.swing.JFrame;
import javax.swing.JLabel;
import back_end.variables;
@SuppressWarnings("serial")
public class label_set extends JFrame{
variables call_vars = new variables();
public void add_labels(){
call_vars.timerheadinglabel = new JLabel("Time till next vote:");
call_vars.votecountlabel = new JLabel("Waiting");
call_vars.label = new JLabel("Waiting");
call_vars.iplabel = new JLabel("Waiting");
call_vars.userlabel = new JLabel("Waiting");
call_vars.lastvoteinfolabel = new JLabel("Last Vote Info");
call_vars.totaltallylabel = new JLabel("Total Tally");
call_vars.timerheadinglabel.setBounds(175, 47, 150, 14);
call_vars.label.setBounds(214, 70, 60, 14);
call_vars.iplabel.setBounds(90, 125, 150, 14);
call_vars.userlabel.setBounds(90, 150, 120, 14);
call_vars.votecountlabel.setBounds(250, 125, 100, 20);
call_vars.lastvoteinfolabel.setBounds(95, 100, 100, 14);
call_vars.totaltallylabel.setBounds(250, 100, 100, 14);
call_vars.panel.add(call_vars.label);
call_vars.panel.add(call_vars.timerheadinglabel);
call_vars.panel.add(call_vars.userlabel);
call_vars.panel.add(call_vars.iplabel);
call_vars.panel.add(call_vars.votecountlabel);
call_vars.panel.add(call_vars.lastvoteinfolabel);
call_vars.panel.add(call_vars.totaltallylabel);
add(call_vars.panel);
setVisible(true);
}
}
here the error is thrown at call_vars.panel.add(call_vars.label); I understand the the call_cars.label is empty and they is why i am getting the error, what i dont know is how i can go about fixing it. Thanks for any help you guys can give!
Nat