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 7580163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:50:53+00:00 2026-05-30T17:50:53+00:00

Try Dim sr As New IO.StreamReader(Mapfile & .txt) ‘Dim intValue As String = Dim

  • 0
    Try
        Dim sr As New IO.StreamReader(Mapfile & ".txt")
        'Dim intValue As String = ""
        Dim strLine As String = ""
        Dim X As Integer = 0
        Dim Y As Integer = 0

        Do Until sr.EndOfStream
            strLine = sr.ReadLine
            strLine = strLine.Replace(strLine.LastIndexOf(","), "")
            For Each item As String In Split(strLine, ",", -1)
                'MsgBox("X:" & X & " Y:" & Y & "= " & item)
                If item = "" Then
                    item = 0
                End If
                If X <= MapWidth Then
                    Map(X, Y, 0) = Int(item)
                End If

                X = X + 1
            Next

            X = 0
            Y = Y + 1
        Loop

        sr.Close()
        sr.Dispose()
    Catch ex As Exception
        MsgBox("Map: " & Mapfile & " could not be loaded." & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Critical, "ERROR")
        IsOn = False
    End Try

Trying to port this code over from Visual Basic To Java. I’ve Tried using Buffered Reader but nothing seems To Make it happen. The Code Above is for Visual Basic, The Code below is my java port that doesnt seem to be working the same. http://pastebin.com/freXYTi3

public void readFile(Context c) {

    BufferedReader br = null;

    try {


      br = new BufferedReader(new InputStreamReader(c.getAssets().open("map1.txt")));
      String line = null;
      String newLine = "";
      int x = 0;
      int y = 0;

      while ((line = br.readLine()) != null) {
        int length = line.length();
        String lastChar = line.substring(length-1);

        if (lastChar.contains(",")) {
            newLine = line.substring(0,length-1) + "";
        }
        //line = line.substring(0, line.lastIndexOf(",")) + "";
        for (String str : line.split(",", -1)) {
        System.out.println(str);
            if(str == ""){
                str = "0";
            }
            if(x <= mapwidth){

                System.out.println(x + " " + y);
                int N = Integer.parseInt(str);
                Map[x][y] = N;

            }

            x = x + 1;
        }
        x = 0;
        y = y + 1;
      }
    }
    catch (FileNotFoundException ex) {
      ex.printStackTrace();
    }
    catch (IOException ex) {
      ex.printStackTrace();
    }
    finally {
      try {
        if (br != null)
          br.close();
      }
      catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }
  • 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-30T17:50:54+00:00Added an answer on May 30, 2026 at 5:50 pm

    Without knowing the exact line you are failing on (the error codes give line numbers, but I don’t know the correlation to your file), the only thing I notice is that this line:

    if(x <= mapwidth){
    

    MIGHT be a one-off bug. I think VB is 1-based and Java is zero based, but it’s just a guess that you might want < rather than <= Can you let us know what line the NPE was on.

    Also this is wrong:

    if(str == ""){
    

    needs to be “str.equals(“”)” or “str.length()==0”

    but I don’t see anything that could cause an NPE within the loop

    Also you assign newline in the loop and you never use it within that scope, so if it exits and you have another “newline” and you expect it to be set–don’t hold your breath.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dim db As New SQLDataContext Try Dim deleteBoatPics = (From boat In db.Photos Where
Imports System.Net Imports System.Net.Mail Public Class Form1 Sub sendMail() Try Dim AnEmailMessage As New
I'm currently downloading an HTML page, using the following code: Try Dim req As
I get the following error message when I try the following: Dim XL As
I have the following code in Visual Studio 2005. Dim OutFile As System.IO.StreamWriter Try
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }
Try to see which cast is faster (not necessary better): new c++ case or
Private Function SendEMail(ByVal sendTo As String, ByVal subject As String) As Boolean Try ''#
I have the following array Dim items() = { New CheckedListBoxItem(NYC, False), New CheckedListBoxItem(CHI,
Here's the code: response.Close() ftpWebRequest = WebRequest.Create(ftp_location & dr(FILE_LOCATION).ToString.Replace(~, )) ftpWebRequest.Credentials = New NetworkCredential(ftp_user,

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.