Hi there,
I am getting a 'Cannot find symbol error' on an array in my "ViewContact" Class. The array has been created in the "MainScreen" class. Below I have pasted the code for both classes as to provide you with as much information as possible:
The MainScreen Class:
package contactkeeper;
import java.io.*;
import java.util.*;
/**
*
* @author Dean Grobler
*/
public class MainScreen extends javax.swing.JFrame{
/** Creates new form MainScreen */
public MainScreen() {
initComponents();
readInfo();
}
//Declare variables
BufferedReader inputStream;
String conInfo;
String infoArray[];
ArrayList<Contact> contactObj = new ArrayList<Contact>();
public void readInfo(){
try{
inputStream = new BufferedReader(new FileReader("conList.txt"));
}
catch(FileNotFoundException e){}
try{
while ((conInfo = inputStream.readLine()) != null) {
infoArray = conInfo.split("\\s+");
//Create new Contact Object
Contact newCon = new Contact(infoArray[0],infoArray[1],infoArray[2],
infoArray[3],infoArray[4],infoArray[5]);
//Add new Contact to ArrayList
contactObj.add(newCon);
}
}
catch(IOException v){}
//Convert ArrayList to Array and Print on MainScreen
int listSize = contactObj.size();
Contact contactArray[];
contactArray = contactObj.toArray(new Contact[listSize]);
for(int i = 0; i < listSize; i++){
MainList.add(contactArray[i].getName()+" "+ contactArray[i].getSurname());
}
}
//Here is just some code that creates the GUI
//And finaly the main mehtod
public static void main(String args[]) {
MainScreen mainscr = new MainScreen();
mainscr.setVisible(true);
}
}
The ViewContact Class:
package contactkeeper;
/**
*
* @author Dean Grobler
*/
public class ViewContact extends javax.swing.JFrame {
/** Creates new form ViewContact */
public ViewContact() {
initComponents();
printInfo();
}
public void printInfo(){
int index = contactkeeper.MainScreen.MainList.getSelectedIndex();
txtName.setText(contactKeeper.mainscr.contactArray[index].getName()); //Error: Cannont find symbol, class mainscr;
}
//Agian just some code that creates the GUI
//And the main method
public static void main(String args[]) {
ViewContact view = new ViewContact();
view.setVisible(true);
}
}
As you can see, the error gets trown in the ViewContact Class, inside the PrintInfo() mehtod. I have added a comment where the error gets thrown. I've been struggling quite a bit in accessing other objects and variables in other classes lately so I think there's something quite obvious that I'm missing here.
Thanks alot guys!