Solved

modify variable of parent class

Posted on 2013-12-06
2
225 Views
Last Modified: 2013-12-06
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
Comment
Question by:Kyle Hamilton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Amitkumar Panchal earned 500 total points
ID: 39700899
It is not initialized that's why you are getting nullpointerexception. You can add a null check before adding to it.
0
 
LVL 25

Author Closing Comment

by:Kyle Hamilton
ID: 39701240
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question