So my problem is that for some reason my AttributeSet is null and I'm not sure how to fix this.
public class MyDocumentFilter extends DocumentFilter {
//TODO FIX THIS, as IS NULL FOR SOME REASON
@Override
public void replace(FilterBypass fb, int i, int o, String s, AttributeSet set) throws BadLocationException{
for(int n = s.length(); n > 0; n--){
char c = s.charAt(n - 1);
System.out.println(set);
if(Character.isAlphabetic(c) || c == ' '){
super.replace(fb, i, o, String.valueOf(c), set);
}else{
JOptionPane.showMessageDialog(null, "Error: Type field must not contain numbers and should be longer than 1 character");
}
}
}
@Override
public void remove(FilterBypass fb, int i, int o) throws BadLocationException{
super.remove(fb, i, o);
}
public void insertString(FilterBypass fb, int i, String s, AttributeSet set) throws BadLocationException{
super.insertString(fb, i, s, set);
}
this is my code, which I had based off of another answer on stackoverflow.(jTextField accept only alphabet and white space)
I could have sworn this worked properly the other day, and when I gave my program test data today it started giving me NullPointerExceptions. I'm completely lost as to why my AttributeSet is null, can someone help?
Edit1: Okay now I'm not completely sure that it's my AttributeSet that's null. I'm also not sure if it's the .replace() method that's the source of the NPE. There is another class where I initialize all my swing components and if I delete out typeField.setText(null) (typeField is the name of the jTextArea), the program doesn't throw NPE anymore. Now I'm even more baffled.