Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

modify variable of parent class

public class Parent{
   String regExpr;
   String target;
   public static ArrayList<Character> language;
   public Regex(String regExpr, String target){
		this.regExpr = regExpr;
		this.target = target;
		this.language = language;
	}
   private class Child{
     void buildLanguage(char c){
         language.add(c);
      }
   }
}

Open in new window


I would like to modify the language variable of the parent class, but I'm getting a java.lang.NullPointerException on the line: language.add(c);

Can this be done?
0
Kyle Hamilton
Asked:
Kyle Hamilton
1 Solution
 
Amitkumar PanchalSr. ConsultantCommented:
It is not initialized that's why you are getting nullpointerexception. You can add a null check before adding to it.
0
 
Kyle HamiltonData ScientistAuthor Commented:
thanks for explaining.

I ended up redesigning the classes, so that the "Child" class is now it's own class, with a public  method that returns the language variable. this means my "Child" class is potentially re-usable in other projects.

cheers.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now