0

So I am trying to build a simple Java program - a Login Interface application - using the Net-beans GUI Builder. See this image if you want to see the Interface design.

Editor: Net-Beans IDE 8.2

Objective: Take in Name and Password input, match them to the Credentials stored and processed in a different class ( which has a public volatile String which holds "true" and "false" as value because I couldn't really implement a proper boolean for a the reason- "Actual parameters don't match the formal parameters"(I assigned a method to the boolean variable) ), and a specific webpage is opened for each successful login which is specific for specific IDs. [ [ NOTE: The passwords in Credentials.java are stored as binary and converted to ASCII using a script and the result is matched with the password input by the user ] ]

Classes Included: Java_007.java( Main class, manages the whole visual interface and sends input data to Credentials.java ) and Credentials.java( Processes the inputs and matches the ID input and Password input to the profiles stored in it )

The Code:
Java_007.java(I have made comments in the code on the extreme left side of the lines)

import java.awt.Desktop;
import java.net.URL;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author walker_001
 */
public class Java_007 extends javax.swing.JFrame {

    /**
     * Creates new form Java_007
     */
    public Java_007() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

//ONLY ASSIGNMENT PART ALONG WITH THE STATUS OF THE OBJECTS(i.e. public, private..)

            back = new javax.swing.JPanel();
            decoration = new javax.swing.JPanel();
            close = new javax.swing.JButton();
            Title = new javax.swing.JLabel();
            name = new javax.swing.JLabel();
            password = new javax.swing.JLabel();
            n = new javax.swing.JTextField();
            ps = new javax.swing.JPasswordField();
            submit = new javax.swing.JButton();
            invalidinput2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setMinimumSize(new java.awt.Dimension(400, 250));
        setUndecorated(true);
        setResizable(false);

        back.setBackground(new java.awt.Color(255, 255, 255));
        back.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 204, 255)));
        back.setForeground(new java.awt.Color(255, 255, 255));
        back.setMaximumSize(new java.awt.Dimension(400, 250));
        back.setMinimumSize(new java.awt.Dimension(400, 250));
        back.setPreferredSize(new java.awt.Dimension(400, 250));

        decoration.setBackground(java.awt.Color.white);
        decoration.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 2, 0, new java.awt.Color(0, 204, 255)));
        decoration.setForeground(new java.awt.Color(255, 255, 255));
        decoration.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                decorationMouseDragged(evt);
            }
        });
        decoration.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                decorationMousePressed(evt);
            }
        });

        close.setBackground(new java.awt.Color(0, 0, 0));
        close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png"))); // NOI18N
        close.setBorder(null);
        close.setBorderPainted(false);
        close.setContentAreaFilled(false);
        close.setFocusPainted(false);
        close.setFocusable(false);
        close.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                closeFocusLost(evt);
            }
        });
        close.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                closeMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                closeMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                closeMouseReleased(evt);
            }
        });
        close.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeActionPerformed(evt);
            }
        });

        Title.setBackground(new java.awt.Color(255, 255, 255));
        Title.setFont(new java.awt.Font("Segoe UI", 1, 18)); // NOI18N
        Title.setForeground(new java.awt.Color(0, 204, 255));
        Title.setText("Login");
        Title.setToolTipText("");

        javax.swing.GroupLayout decorationLayout = new javax.swing.GroupLayout(decoration);
        decoration.setLayout(decorationLayout);
        decorationLayout.setHorizontalGroup(
            decorationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, decorationLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(Title)
                .addGap(139, 139, 139)
                .addComponent(close, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        decorationLayout.setVerticalGroup(
            decorationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(decorationLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(close, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(Title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        name.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        name.setForeground(new java.awt.Color(0, 204, 255));
        name.setText("Name : ");

        password.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        password.setForeground(new java.awt.Color(0, 204, 255));
        password.setText("Password : ");

        n.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        n.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        n.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 2, 0, new java.awt.Color(0, 204, 255)));
        n.setCaretColor(new java.awt.Color(0, 204, 255));
        n.setMaximumSize(new java.awt.Dimension(192, 26));
        n.setMinimumSize(new java.awt.Dimension(192, 26));
        n.setPreferredSize(new java.awt.Dimension(192, 26));
        n.setSelectedTextColor(new java.awt.Color(255, 255, 255));
        n.setSelectionColor(new java.awt.Color(0, 204, 255));
        n.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                nFocusGained(evt);
            }
        });

        ps.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        ps.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        ps.setToolTipText("");
        ps.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 2, 0, new java.awt.Color(0, 204, 255)));
        ps.setCaretColor(new java.awt.Color(0, 204, 255));
        ps.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        ps.setEchoChar('\u2219');
        ps.setSelectedTextColor(new java.awt.Color(255, 255, 255));
        ps.setSelectionColor(new java.awt.Color(0, 204, 255));
        ps.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                psFocusGained(evt);
            }
        });

        submit.setBackground(new java.awt.Color(0, 0, 0));
        submit.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
        submit.setForeground(new java.awt.Color(0, 204, 255));
        submit.setText("Submit");
        submit.setToolTipText("");
        submit.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 2, 0, new java.awt.Color(0, 204, 255)));
        submit.setContentAreaFilled(false);
        submit.setFocusPainted(false);
        submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitActionPerformed(evt);
            }
        });

        invalidinput2.setFont(new java.awt.Font("Segoe UI", 1, 12)); // NOI18N
        invalidinput2.setForeground(new java.awt.Color(255, 0, 0));
        invalidinput2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout backLayout = new javax.swing.GroupLayout(back);
        back.setLayout(backLayout);
        backLayout.setHorizontalGroup(
            backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(decoration, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, backLayout.createSequentialGroup()
                .addGap(60, 60, 60)
                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(submit, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(backLayout.createSequentialGroup()
                            .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(name)
                                .addComponent(password))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(ps)
                                .addComponent(n, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addComponent(invalidinput2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(60, 60, 60))
        );
        backLayout.setVerticalGroup(
            backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backLayout.createSequentialGroup()
                .addComponent(decoration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(invalidinput2, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(name)
                    .addComponent(n, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(backLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(password)
                    .addComponent(ps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(submit, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(back, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(back, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void closeActionPerformed(java.awt.event.ActionEvent evt) {                                      
        System.exit(0);
    }

//REAL CODE STARTS HERE. Continuing Java_007.java's code below...

    //user defined variables...start
    int xmouse;
    int ymouse; 
    Credentials c= new Credentials();
    //user defined variables...end

    private void closeMousePressed(java.awt.event.MouseEvent evt) {                                   
        close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close_pressed.png")));
    }                                  

    private void decorationMouseDragged(java.awt.event.MouseEvent evt) {                                        
        int x= evt.getXOnScreen();
        int y= evt.getYOnScreen();

        setLocation(x - xmouse, y - ymouse);
    }                                       

    private void decorationMousePressed(java.awt.event.MouseEvent evt) {                                        
        xmouse= evt.getX();
        ymouse= evt.getY();
    }                                       

    private void submitActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String a= n.getText();
        String b= ps.getText();
        if (a.equals("") || b.equals("")){
            if (a.equals("") && b.equals("")){
                n.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(255, 0, 0)));
                ps.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(255, 0, 0)));
                invalidinput2.setText("Please enter your name and password.");
            }
            else if(a.equals("")){
                n.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(255, 0, 0)));
                invalidinput2.setText("Please enter your name.");
            }
            else if(b.equals("")){
                ps.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(255, 0, 0)));
                invalidinput2.setText("Please enter your password.");
            }
        }
        else{
            if (a.equals(Credentials.a1) && c.encoded.equals("true")){
                try {
                    Desktop.getDesktop().browse(new URL("https://inbox.google.com/").toURI());
                } catch (Exception e) {}
                System.exit(0);
            }
            else if (a.equals(Credentials.a2) && c.encoded.equals("true")){
                try {
                    Desktop.getDesktop().browse(new URL("https://www.google.com/").toURI());
                } catch (Exception e) {}
                System.exit(0);
            }
            else if (a.equals(Credentials.a3) && c.encoded.equals("true")){
                try {
                    Desktop.getDesktop().browse(new URL("https://images.google.com/").toURI());
                } catch (Exception e) {}
                System.exit(0);
            }
            else{
                invalidinput2.setText("Invalid Credentials");
                //System.out.println(c.id);System.out.println(Credentials.pd);System.out.println(Credentials.passwrd);System.out.println(Credentials.psv);System.out.println(Credentials.encoded);
            }
            n.setText("");
            ps.setText("");
        }

    }                                      

    private void nFocusGained(java.awt.event.FocusEvent evt) {                              
        n.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 255, 255)));
        ps.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 255, 255)));
            invalidinput2.setText("");
    }                             

    private void psFocusGained(java.awt.event.FocusEvent evt) {                               
        n.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 255, 255)));
        ps.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(0, 255, 255)));
            invalidinput2.setText("");
    }                              

    private void closeMouseExited(java.awt.event.MouseEvent evt) {                                  
        close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png")));
    }                                 

    private void closeMouseReleased(java.awt.event.MouseEvent evt) {                                    
        close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png")));
    }                                   

    private void closeFocusLost(java.awt.event.FocusEvent evt) {                                
        close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Close.png")));
    }                               


    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Java_007.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Java_007.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Java_007.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Java_007.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java_007().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JLabel Title;
    private javax.swing.JPanel back;
    private javax.swing.JButton close;
    private javax.swing.JPanel decoration;
    private javax.swing.JLabel invalidinput2;
    public static javax.swing.JTextField n;
    private javax.swing.JLabel name;
    private javax.swing.JLabel password;
    public static javax.swing.JPasswordField ps;
    public volatile javax.swing.JButton submit;
    // End of variables declaration                   
}

Credentials.java

public class Credentials{
    public static String a1= "Strix";
    public static String a2= "PK";
    public static String a3= "Molt";

    static String b1= "0010001100110000011110000101011101001101001100010011000001011000";
    static String b2= "00110000001100000011000000110010001101100011100000110100";
    static String b3= "00110001001100100011001100110100";

    volatile String id= Java_007.n.getText();
    volatile String pd= Java_007.ps.getText();
    volatile String passwrd= passwrd(id);

    volatile String psv= psV(passwrd);

    public volatile String encoded= post(psv);

    public static void main(String[] args) {
        //System.out.println(id);System.out.println(pd);System.out.println(passwrd);System.out.println(psv);System.out.println(encoded);
    }

    private String passwrd(String password){
        if (id.equals(a1)){
            password= b1;
        }
        else if (id.equals(a2)){
            password= b2;
        }
        else if (id.equals(a3)){
            password= b3;
        }else{}
        return password;
    }

    private String psV(String e){
        StringBuilder b = new StringBuilder();
        int len = passwrd.length();
        int i = 0;
        while (i + 8 <= len) {
            char c = convert(passwrd.substring(i, i+8));
            i+=8;
            b.append(c);
            e= b.toString();
        }
        return e;

    }

    private static char convert(String bs) {
      return (char)Integer.parseInt(bs, 2);
    }

    private String post(String r){
        boolean go= false;
        if (id.equals(a1)){
            if (pd.equals(psv)){
                go= true;
            }
            else{
                go= false;
            }
        }
        else if (id.equals(a2)){
            if (pd.equals(psv)){
                go= true;
            }
            else{
                go= false;
            }
        }
        else if (id.equals(a3)){
            if (pd.equals(psv)){
                go= true;
            }
            else{
                go= false;
            }
        }
        else{
            go= false;
        }

        if (go == true){
            r= "true";
        }
        else{
            r= "false";
        }

        return r;
    }

}





The Problem: The program doesn't show up at all. Net-Beans doesn't show any error while compiling, but when I run the program, the output pane shows a NullPointerException:

run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Credentials.<init>(Credentials.java:10)
    at Java_007.<init>(Java_007.java:240)
    at Java_007$9.run(Java_007.java:361)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 1 second)



I have been searching the Internet since yesterday but I couldn't really find a solution. I am sure it is something related to volatile declaration of some variables in the Credentials.java class and maybe some other declarations related to the processing in Java_007.java file too, but I'm not sure what exactly is the problem. Any help will be appreciated! Thank you for reading this. Feel free to request any additional information that I might have not provided.

  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Alexander Jun 20 '17 at 08:32
  • but i tried to use "encoded= new post(psv);" to instantiate the variable but it says cannot find symbol when post() method is in the same class. – Pratyush Kumar Jun 20 '17 at 08:43
  • i also tried to refer to the Credentials.java's variables using a local variable as `Credentials c= new Credentials();` in the Java_007.java file – Pratyush Kumar Jun 20 '17 at 08:46
  • The problem is that the members in `Credentials.java` try to invoke non-initializied variables in the `Java_007.java`. Besides that your class naming and class design has space for improvement, this just dosn't work. from `Credentials` : `volatile String id= Java_007.n.getText();` from `Java_007`: `public static javax.swing.JTextField n;` -> "n" is undefined! So calling `getText` on a null variable causes the NPE. Please rethink your class design. – Alexander Jun 20 '17 at 10:04
  • @Alexander oh i see now! I did a bad thing there...and i just started java so ya...there is a lot of room for improvement – Pratyush Kumar Jun 21 '17 at 06:55
  • I'll see what I can do – Pratyush Kumar Jun 21 '17 at 07:00
  • @Alexander should i even use volatile variables for this project? – Pratyush Kumar Jun 21 '17 at 08:36
  • In general I'd say *keep it simple*. But it shouldn't matter whether the variables are volatile or not - it's more important that you design the interfaces between your classes ("who passed which value to which class and when"). Use Getters/Setters to get/set the values or pass variables in the constructor, but don't access members of another class directly! Regarding the volatile question: Did you have a look at https://stackoverflow.com/questions/106591/do-you-ever-use-the-volatile-keyword-in-java ? – Alexander Jun 21 '17 at 08:51
  • @Alexander very well, I am gonna rethink the whole code now i guess, I think I did some planning mistake... Thanks for your help! Have a Great Day – Pratyush Kumar Jun 21 '17 at 12:00

1 Answers1

0

So it turns out that I was calling methods/instance before they were even created... I tried some things I could think of such as not using direct getters instead accessing a variable.. the NullPointerException was resolved, but there were some code planning problems. So now I am going to rethink the whole planning and dump this code. GOOD DAY ALL!