The following code generates this error message and I'm not exactly sure why: "non-static variable charArray cannot be referenced from a static context." The code is here:
import java.util.*;
public class MyClass{
String userInput;
char[] charArray;
public static void main(String args[]){
MyClass testString = new MyClass("hello");
for(int i = 0; i < charArray.length; i++){
}
}
MyClass(String input){
userInput = input;
charArray = input.toCharArray();
}
}
Any suggestions on how to fix this?