Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Intializing data variable error?

  Asked By: Bakir    Date: Jun 02    Category: Java    Views: 758
  

I'm working on an app and have come into a problem with part of the code:
First here it is:

FileReader languagefile;
BufferedReader bufferlan;
String[] codeName = new String[700];
String[] translation = new String[700];
int translationNum = 0;
int codeNum = 0;
int numberLine = 0;
try
{
languagefile = new FileReader(completefile);
bufferlan = new BufferedReader(languagefile);
String temp = null;
while((temp=bufferlan.readLine()) != null)
{
if(((numberLine/2) % 2) == 1)
{
codeName[codeNum] = bufferlan.readLine();
codeNum ++;
}//end if
else
{
translation[translationNum] = bufferlan.readLine();
translationNum ++;
}//end else
}//end while
bufferlan.close();
languagefile.close();
JLabel title = new JLabel(text);
Object[][] data;
int rowNum = 0;
while(rowNum <= codeNum)
{rowNum = 0;
data[rowNum][0] = codeName[rowNum];
data[rowNum][1] = translation[rowNum];
}
String[] columnNames = {"Code Name","Translation"};

JTable table = new JTable(data, columnNames);
JScrollPane scrollPane = new JScrollPane(table);
LanguagePanel.add(title);
LanguagePanel.add(scrollPane);
}//end try
catch( IOException e )
{
System.out.println(e);
}
return LanguagePanel;
}

It is when I try to compile my code that I get these two errors:

variable data might not have been initialized
data[rowNum][0] = codeName[rowNum];
& the same for this line:
JTable table = new JTable(data, columnNames);

The arrow below them points first to the codeName variable then secondly to
the columnNames variable.
Please any help would be greatly apprecaited :)
BTW the two variable completefile and languageFile are set up further up the
code.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Freda Lane     Answered On: Jun 02

That is because you declare your data  array without actually initializing it:

Object[][] data;

Should become:

Object[][] data = new Object[x][y];

Where x and y are the size of your multi-dimensional array.

 
Didn't find what you were looking for? Find more on Intializing data variable error? Or get search suggestion and latest updates.




Tagged: