Solved

modify variable of parent class

Posted on 2013-12-06
2
219 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 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
allswap challenge 6 96
VB Script to add site to Java Exception List 4 76
spring jars download 1 26
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

776 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