# nullPointerException bei [ArrayList<String>.add(.)]



## hamburger_1983 (10. Okt 2007)

Hallo,

wie ihr vielleicht in der Überschrift sehen könnt, habe ich eine nullPointerException. Leider weiss ich nicht warum.


```
package ...

import java.util.ArrayList;

public class PhoneticSearch {
	
	private ArrayList<String[]> searchGroups;
	private String exampleValue;

	private String[] phoneticGroupEI = {"ei","eih","ay","ey","ei","eij"};
	private String[] phoneticGroupA = {"a","ah","ar","er"};
	private String[] phoneticGroupE = {"e","ä","äh","ae","aeh","ai"};
	private String[] phoneticGroupI = {"i","j","ie","ich","ieh","ü","ij"};
	private String[] phoneticGroupOE = {"ö","oe","oeh","öh"};
	private String[] phoneticGroupJ = {"j","y","ue","üe","ui","ueh","üh"};
	private String[] phoneticGroupO = {"o","oh"};
	private String[] phoneticGroupU = {"u","uh"};
	private String[] phoneticGroupEU = {"eu","äu","aeu","oi","oy"};
	private String[] phoneticGroupG = {"g","k","c","qu","cc","ch","ck","kk"};
	private String[] phoneticGroupQU = {"qu","kw"};
	private String[] phoneticGroupSCH = {"sch","ch","sh"};
	private String[] phoneticGroupB = {"b","p"};
	private String[] phoneticGroupD = {"d","t","dt","dh","th"};
	private String[] phoneticGroupGJ = {"g","j"};
	private String[] phoneticGroupSS = {"ss","s","ß","sz","c"};
	private String[] phoneticGroupW = {"w","v","f","ph"};
	private String[] phoneticGroupX = {"x","ks","gs","chs","cs"};
	private String[] phoneticGroupZ = {"z","c","tz","ts"};
	private String[] phoneticGroupDim = {"Dim","Dm"};
	private String[] phoneticGroupOA = {"O","A"};
	private String[] phoneticGroupDer = {"der","dar","dr"};
	
	public ArrayList<String> PhoneticSearch(String exampleValue) {

		this.exampleValue = exampleValue;
		
		ArrayList<String[]> foundedGroups = findPhoneticMatches();
		ArrayList<String> resultList = getAppliedPhoneticGroup(foundedGroups);
		
		return resultList;
		
	}	
		
	private ArrayList<String[]> findPhoneticMatches() {

		this.searchGroups.add(this.phoneticGroupEI);
		this.searchGroups.add(this.phoneticGroupA);
		this.searchGroups.add(this.phoneticGroupE);
		this.searchGroups.add(this.phoneticGroupI);
		this.searchGroups.add(this.phoneticGroupOE);
		this.searchGroups.add(this.phoneticGroupJ);
		this.searchGroups.add(this.phoneticGroupO);
		this.searchGroups.add(this.phoneticGroupU);
		this.searchGroups.add(this.phoneticGroupEU);
		this.searchGroups.add(this.phoneticGroupG);
		this.searchGroups.add(this.phoneticGroupQU);
		this.searchGroups.add(this.phoneticGroupSCH);
		this.searchGroups.add(this.phoneticGroupB);
		this.searchGroups.add(this.phoneticGroupD);
		this.searchGroups.add(this.phoneticGroupGJ);
		this.searchGroups.add(this.phoneticGroupSS);
		this.searchGroups.add(this.phoneticGroupW);
		this.searchGroups.add(this.phoneticGroupX);
		this.searchGroups.add(this.phoneticGroupZ);
		this.searchGroups.add(this.phoneticGroupDim);
		this.searchGroups.add(this.phoneticGroupOA);
		this.searchGroups.add(this.phoneticGroupDer);
		
		ArrayList<String[]> foundedGroups = new ArrayList<String[]>(); 
		for (int i=0; i<this.searchGroups.size(); i++) {
			for (int j=0; j<this.searchGroups.get(i).length;j++) {
				if ((this.exampleValue.contains(this.searchGroups.get(i)[j]))) {
					foundedGroups.add(this.searchGroups.get(i));
					break;
				}
			}
		}
		return foundedGroups;
	}
	
	public ArrayList<String> getAppliedPhoneticGroup(ArrayList<String[]> group) {
		ArrayList<String> resultGroup = new ArrayList<String>();
		resultGroup.add(this.exampleValue);
		for (int i=0; i<group.size(); i++) {
			for (int j=0; j<group.get(i).length;j++) {
				if (this.exampleValue.contains(group.get(i)[j])) {
					for (int k=0; k<group.get(i).length;k++) {
						String result = this.exampleValue.replace(group.get(i)[j],group.get(i)[k]);
						if (!resultGroup.contains(result)) {
							resultGroup.add(result);
						}
					}
				}
			}
		}
		return resultGroup;
	}

}
```

Der Fehler soll laut Consolenausgabe und Debuger in Zeile 46 (und damit wohl auch in den Zeilen 47, 48, ... 67) auftreten:


```
this.searchGroups.add(this.phoneticGroupEI);
```


----------



## Gast (10. Okt 2007)

searchGroups ist null, weil nicht initialisiert.

Micha


----------



## hamburger_1983 (10. Okt 2007)

???:L  hmm

wie kann ich denn dann eine leere Liste initilisieren?


Edith: Ok, hat sich erledigt, gibt aber neues Problem, werde mal erforschen, was jetzt falsch ist,


----------



## Gast (10. Okt 2007)

private ArrayList<String[]> searchGroups = new ArrayList<String[]>();


----------

