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

    Default 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
      • start_gui_bot.java
    • GUI_components
      • label_set.java

    And here is the code for the main class (start_gui_bot.java):

    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:

    Java 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
    Last edited by nat45928; 05-09-2011 at 10:39 PM.

Similar Threads

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