hello all
Today I wrote a simple java program but it's error will make me crazy!
the program got this error:
Exception in thread "main" java.lang.NullPointerException.
there is only two class in my program (Triple and parse).
I have an array of the first class type in the second class.(static Triple[][] sentencesTriples= new Triple[...][...]
when I try to call a function of the first class in the second class, it got the mentioned error message.
(sentencesTriples[currentRow][currentColumn++].set(tokens[0], tokens[1], tokens[3])
do you have any idea to solve this problem?
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class parse{
static int currentRow=0;
static int currentColumn=0;
static int numOfSentences=50;
static int maxNumOfRelations=40;
static Triple[][] sentencesTriples= new Triple[numOfSentences][maxNumOfRelations];
@SuppressWarnings("null")
public static void main(String[] args){
currentRow=0;
currentColumn=0;
try {
File fileSourceDependency = new File("C:/Users/green/Documents/NetBeansProjects/parsDependency/collapsed dependency for suppose in M_Tr.txt");
File outFile = new File("C:/Users/green/Documents/NetBeansProjects/parsDependency/matchSentences.txt");
BufferedReader inDependency = new BufferedReader(
new InputStreamReader(
new FileInputStream(fileSourceDependency), "UTF8"));
String strEn;
try {
Writer out_dependency_match = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "UTF8"));
while ((strEn = inDependency.readLine()) != null ) {
if(strEn.isEmpty()){
currentRow++;
currentColumn=0;
strEn=inDependency.readLine();
}
String[] tokens=new String[5];
for(int i=0; i<5;i++) tokens[i]=null;
StringTokenizer st;
st = new StringTokenizer(strEn," ");
for(int i=0;i<5;i++) tokens[i]=st.nextToken();
System.out.print(currentRow+" "+currentColumn+" "+tokens[0]+ tokens[1]+ tokens[3]+" ");
sentencesTriples[currentRow][currentColumn++].set(tokens[0], tokens[1], tokens[3]);
}
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
for (int i=0;i<20;i++)
for(int j=0;j< 5;j++){
System.out.println(sentencesTriples[i][j].getRelation()+" "+sentencesTriples[i][j].getArg1()
+" "+sentencesTriples[i][j].getArg2());
}
System.out.println("**End**");
}
}