Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

Cannot read JTextArea it shows : cannot read "JTextArea Variable" because "this.SuperClass Variable" is null

user-aqfuwMay 25 2023
package key_master1;

import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Arrays;
import javax.swing.JOptionPane;

public class Working{
    String paragraph = "Example";
    
    public Key_Master1 key;  //To Access Another Class Variable Create Variable for Superclass


public void addTextAreaListener() throws Exception{  //Create a Method 
    key.canvas.addKeyListener(new KeyListener(){
        @Override
        public void keyTyped(KeyEvent e) {
            //throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
            paragraph = e.toString();
            String[] words = paragraph.split(" ");
            for (String word : words){
                if(word.equalsIgnoreCase(word)){
                    JOptionPane.showMessageDialog(key.con,"In this Paragraph the word  \""+word+"\" is wrongly typed  so correct it before you type");
                }
            }
            
        }

        @Override
        public void keyPressed(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
        }

        @Override
        public void keyReleased(KeyEvent e) {
            throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
        }
        
    });
    
}

I Have Given my Working Code. I Will be grateful if someone helps me

Comments
Post Details
Added on May 25 2023
2 comments
175 views