Results 1 to 5 of 5
  1. #1
    afisher300 is offline Member
    Join Date
    Mar 2008
    Location
    Colorado
    Posts
    6
    Rep Power
    0

    Default New to this - having errors with static problems

    I am having errors with static problems. I dont know if I post what i have done and what I am trying to accomplish and show the errors. Could someone help me out on how I should do my posts? Thanks in advance...

    Amy

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Post any code you have developed (use code tags), a brief description what the program should do and any exact error messages (cut & paste) that are displayed.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    afisher300 is offline Member
    Join Date
    Mar 2008
    Location
    Colorado
    Posts
    6
    Rep Power
    0

    Default Trying to figure out static problems...

    here it goies. It is a program that will go through and has to check 6 passwords and has to have 9 different methods, but it has to be in a cetain order. That is you rinstantiate a password object- that is what I think I did by making it mypassword.??? Then you have a for loop, then you need a method for startPasswordChecker, then callInput and several more. the class will have a default constructor(no parameter) that sets all the counder to zeros ( I am a little confused on this)I was stupid and wrote the whole program then compile, ended up with so many errors, started over and thought I would kind of do baby steps. So I will so the program that I have and then the errors. If I do this wrong I am sorry and if some one can tell me how to do it right I woudl apprecitate it. Thank you in advance.

    here is the program I have:

    import javax.swing.*; //to use JOptionPane

    public class PasswordTest
    {
    private String passwordsBeingEntered;
    private String testPlansAuthor;

    private int numberOfPasswords;
    private int validPassword;
    private int badPassword;
    private int index;

    private boolean checkLength = false;
    private boolean checkLowercase = false;
    private boolean checkUppercase = false;
    private boolean checkDigit = false;


    public static void startPasswordChecker()
    {
    System.out.println("Please welcome to the Password Checker Program" +
    "\n\nThis prgram asks the user how many passwords they choose to check" +
    "\n and the computer will determine how many of the passwords are valid and how many are bad");




    numberOfPasswords = Integer.parseInt(JOptionPane.showInputDialog("Plea se enter how many " +
    "passwords you would like to check?"));



    testPlansAuthor = (JOptionPane.showInputDialog("Please enter your name?"));

    System.out.println("the program just asked for the name of the participant");

    // this string that will help with the output at the end of the program
    String reportString = ("Results of Password Checker" +
    "\n\nTest plans were made by " + testPlanAuthor +
    "\nPasswords checked:" + numberOfPasswords +
    "\n Good Passwords:" + validPassword + " bad Passwords" + badPassword);

    }// end of startPasswordChecker method

    public static void inputPassword()
    {
    passwordsBeingEntered(index)= (JOptionPane.showInputDialog("Please enter your password?"));

    }//end of inputPasswordMethod

    public static void main(String[] args)
    {
    Password mypassword = new Password();

    for (index = 1; index <= numberOfPasswords; index++)
    { mypassword.startPasswordChecker();
    mypassword.inputPassword();
    }
    }// end of main

    }// end of class PasswordTest

    Here are the errors I am receiving

    PasswordTest.java:28: non-static variable numberOfPasswords cannot be referenced from a static context
    numberOfPasswords = Integer.parseInt(JOptionPane.showInputDialog("Plea se enter how many " +
    ^
    PasswordTest.java:33: non-static variable testPlansAuthor cannot be referenced from a static context
    testPlansAuthor = (JOptionPane.showInputDialog("Please enter your name?"));
    ^
    PasswordTest.java:39: cannot find symbol
    symbol : variable testPlanAuthor
    location: class PasswordTest
    "\n\nTest plans were made by " + testPlanAuthor +
    ^
    PasswordTest.java:40: non-static variable numberOfPasswords cannot be referenced from a static context
    "\nPasswords checked:" + numberOfPasswords +
    ^
    PasswordTest.java:41: non-static variable validPassword cannot be referenced from a static context
    "\n Good Passwords:" + validPassword + " bad Passwords" + badPassword);
    ^
    PasswordTest.java:41: non-static variable badPassword cannot be referenced from a static context
    "\n Good Passwords:" + validPassword + " bad Passwords" + badPassword);
    ^
    PasswordTest.java:47: non-static variable index cannot be referenced from a static context
    passwordsBeingEntered(index)= (JOptionPane.showInputDialog("Please enter your password?"));
    ^
    PasswordTest.java:47: cannot find symbol
    symbol : method passwordsBeingEntered(int)
    location: class PasswordTest
    passwordsBeingEntered(index)= (JOptionPane.showInputDialog("Please enter your password?"));
    ^
    Password.java:29: not a statement
    "passwords you would like to check?"));
    ^
    Password.java:29: ';' expected
    "passwords you would like to check?"));
    ^
    PasswordTest.java:55: non-static variable index cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    PasswordTest.java:55: non-static variable index cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    PasswordTest.java:55: non-static variable numberOfPasswords cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    PasswordTest.java:55: non-static variable index cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    PasswordTest.java:57: cannot find symbol
    symbol : method inputPassword()
    location: class Password
    mypassword.inputPassword();
    ^
    Password.java:31: non-static variable testPlansAuthor cannot be referenced from a static context
    testPlansAuthor = (JOptionPane.showInputDialog("Please enter your name?"));
    ^
    Password.java:41: non-static variable index cannot be referenced from a static context
    passwords(index) = JOptionPane.showInputDialog("Please enter all of your passwords one at a time?");
    ^
    Password.java:41: cannot find symbol
    symbol : method passwords(int)
    location: class Password
    passwords(index) = JOptionPane.showInputDialog("Please enter all of your passwords one at a time?");
    ^
    Password.java:50: non-static variable index cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    Password.java:50: non-static variable index cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    Password.java:50: non-static variable numberOfPasswords cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    Password.java:50: non-static variable index cannot be referenced from a static context
    for (index = 1; index <= numberOfPasswords; index++)
    ^
    22 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

  4. #4
    tomiu is offline Member
    Join Date
    Dec 2008
    Posts
    32
    Rep Power
    0

    Default

    Well as the error shows, u try to reference a non-static variable, from the static method main..

    u either declare the variable as static (for example)
    Java Code:
    private static int numberOfPasswords;
    or u create an object of the class PasswordTest and than access the instance variables (object name, then a dot, then the variable)
    Last edited by tomiu; 04-20-2009 at 11:46 PM.

  5. #5
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    Check out the java trail's explanation on static and non-static variables.

    And next time remember to use code tags. When you click the Post Reply button you will see the text area with buttons on the top. Click the button that has the symbol '#' to insert the code tags. Place all of your code in-between the tags.

    Mr. Beans
    Last edited by Mr.Beans; 04-21-2009 at 12:45 AM.

Similar Threads

  1. Replies: 3
    Last Post: 03-08-2009, 02:51 AM
  2. Replies: 5
    Last Post: 02-04-2009, 02:20 AM
  3. Static variable context Errors ?
    By Shyam Singh in forum New To Java
    Replies: 16
    Last Post: 08-08-2008, 10:11 PM
  4. Replies: 1
    Last Post: 08-07-2007, 06:05 AM
  5. Replies: 1
    Last Post: 08-01-2007, 10:25 PM

Posting Permissions

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