Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4067204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:13:13+00:00 2026-05-20T16:13:13+00:00

I’m trying to convert a method that I have written in C# to Java

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:13:13+00:00Added an answer on May 20, 2026 at 4:13 pm

    You don’t say where it is but I am betting it is here…

    line[colCurrentLevel*screenCols + currentCol]
    

    Which should be using String’s charAt() since lines are not treated as char arrays in Java…

    line.charAt(colCurrentLevel*screenCols + currentCol)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.