Results 1 to 1 of 1
  1. #1
    nat45928 is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Multiple classes error


    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
    • bot
    • GUI_components

    And here is the code for the main class (

    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 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;
    	    setSize(480, 250);
    	    call_vars.panel = new JPanel();
    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();
    		if ( variables.set_tor == "true" ) {
    		for (int i = 1; i <= variables.make_vote_number; i++){ ();
    the error is thrown at ls.add_labels(); so here is its code:

    Java Code:
    package GUI_components;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import back_end.variables;
    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);
    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!

    Last edited by nat45928; 05-09-2011 at 09:39 PM.

Similar Threads

  1. Multiple images from different classes
    By superbriggs in forum Java 2D
    Replies: 1
    Last Post: 03-20-2011, 08:59 AM
  2. Multiple classes
    By Lund01 in forum New To Java
    Replies: 1
    Last Post: 03-16-2011, 02:58 PM
  3. help with GUI and multiple classes
    By sssss in forum Advanced Java
    Replies: 14
    Last Post: 01-16-2011, 10:08 PM
  4. Help with multiple frames/classes
    By Celletti in forum AWT / Swing
    Replies: 1
    Last Post: 04-28-2010, 03:18 AM
  5. How to use multiple timer classes in swings
    By theone3nu in forum AWT / Swing
    Replies: 12
    Last Post: 12-30-2008, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts