Java 2 dimensional array of Strings error -
public class robotzoneclass implements robotzone { string[][] map; public robotzoneclass(int rows, int columns){ map= new string[rows][columns]; } public void readmap(string map,int row) { for(int i=0;i<map.length()-1;i++){ map[row][i]=map.charat(i); } } } i error: the type of expression must array type resolved string. why happening?
you shadowing global map variable:
in computer programming, variable shadowing occurs when variable declared within scope (decision block, method, or inner class) has same name variable declared in outer scope.
rename parameter readmap:
public void readmap(string othermap,int row) { for(int i=0;i<map.length()-1;i++){ map[row][i]=othermap.charat(i); } } also, seems you're using two-dimensional array of strings (which three-dimensional array of characters) map when want two-dimensional character array, array of strings.
try this:
public class robotzoneclass implements robotzone { string[] map; public robotzoneclass(int rows){ map = new string[rows]; } public void readmap(string newrow, int row) { // replaces row in map map[row]=newrow; } // rest of implementation }
Comments
Post a Comment