Results 1 to 5 of 5
- 04-20-2009, 08:40 PM #1
Member
- Join Date
- Mar 2008
- Location
- Colorado
- Posts
- 6
- Rep Power
- 0
- 04-20-2009, 08:45 PM #2
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 04-20-2009, 09:02 PM #3
Member
- Join Date
- Mar 2008
- Location
- Colorado
- Posts
- 6
- Rep Power
- 0
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.
- 04-20-2009, 10:42 PM #4
Member
- Join Date
- Dec 2008
- Posts
- 32
- Rep Power
- 0
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)
or u create an object of the class PasswordTest and than access the instance variables (object name, then a dot, then the variable)Java Code:private static int numberOfPasswords;
Last edited by tomiu; 04-20-2009 at 10:46 PM.
- 04-20-2009, 11:42 PM #5
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. BeansLast edited by Mr.Beans; 04-20-2009 at 11:45 PM.
Similar Threads
-
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
Debuggin help - simple program non-static method errors
By RR_QQ in forum New To JavaReplies: 5Last Post: 02-04-2009, 01:20 AM -
Static variable context Errors ?
By Shyam Singh in forum New To JavaReplies: 16Last Post: 08-08-2008, 09:11 PM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks