I'm trying to convert a method that I have written in C# to Java for Android.
The following coding is what I'm trying to convert from C# to Java:
public Map()
{
string line;
int maxRowLevels, maxColLevels;
StreamReader file;
file = File.OpenText("map.txt");
line = file.ReadLine();
line = file.ReadLine();
maxRowLevels = System.Convert.ToInt32(line) - 1;
line = file.ReadLine();
line = file.ReadLine();
maxColLevels = System.Convert.ToInt32(line) - 1;
line = file.ReadLine();
map = new char[maxRowLevels+1,maxColLevels+1,screenRows,screenCols];
for (int rowCurrentLevel = 0; rowCurrentLevel<=maxRowLevels; rowCurrentLevel++)
{
for (int currentRow = 0; currentRow<screenRows; currentRow++)
{
line = file.ReadLine();
for (int colCurrentLevel = 0; colCurrentLevel<=maxColLevels; colCurrentLevel++)
{
for (int currentCol = 0; currentCol<screenCols; currentCol++)
{
map[rowCurrentLevel, colCurrentLevel,currentRow, currentCol] = line[colCurrentLevel*screenCols + currentCol];
}
}
}
}
file.Close();
}
My attempt to conversion is the following code:
public Map(Context context)
{
String line;
int maxRowLevels, maxColLevels;
int maxRowLevels, maxColLevels;
InputStream inputFile;
BufferedReader file;
inputFile = context.getAssets().open("map.txt");
file = new BufferedReader(new InputStreamReader(inputFile, "UTF-8"));
line = file.readLine();
line = file.readLine();
maxRowLevels = Integer.parseInt(line)-1;
line = file.readLine();
line = file.readLine();
maxColLevels = Integer.parseInt(line)-1;
line = file.readLine();
mapa = new char[maxRowLevels+1][maxColLevels+1][screenRows][screenCols];
for (int rowCurrentLevel = 0; rowCurrentLevel<=maxRowLevels; rowCurrentLevel++)
{
for (int currentRow = 0; currentRow<screenRows; currentRow++)
{
line = file.readLine();
for (int colCurrentLevel = 0; colCurrentLevel<=maxColLevels; colCurrentLevel++)
{
for (int currentCol = 0; currentCol<screenCols; currentCol++)
{
mapa[rowCurrentLevel][colCurrentLevel][currentRow][currentCol] = line[colCurrentLevel*screenCols + currentCol];
}
}
}
}
inputFile.close();
file.close();
}
It seems everything is correct except for this line that drops this error: "the type of the expression Must Be an array type string But It resolved to string"
mapa[rowCurrentLevel][colCurrentLevel][currentRow][currentCol] = line[colCurrentLevel*screenCols + currentCol]
;
Can anyone tell me how to fix it? I think that it will be silly, forgive me but I am a begginer in Java.
Thanks in advance.