arrays - Java: Local variable scope -


i error saying compiler cannot find variable "complexarray" don't know why. how fix program returns array of complex numbers read file?

public static complex[] parsefromfile(string filename) {     int numofcomplex = 0;     try {            scanner sc = new scanner(new file(filename));         string firstline = sc.nextline();         firstline = firstline.trim();         numofcomplex = integer.parseint(firstline);         complex[] complexarray = new complex[numofcomplex];         (int = 0; < numofcomplex; i++) {             string nextline = sc.nextline();             nextline = nextline.trim();             complexarray[i] = parsecomplex(nextline);         }     }     catch(exception e) {     }     return complexarray; } 

your complexarray variable declared inside try{} scope. declare before try statement.

complex[] complexarray = null;


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -