Solved

modify variable of parent class

Posted on 2013-12-06
2
216 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
2 Comments
 
LVL 20

Accepted Solution

by:
Amitkumar Panchal earned 500 total points
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now