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

  • SEARCH
  • Home
  • 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 6999551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:33:22+00:00 2026-05-27T20:33:22+00:00

I’ve written a application in Java which I am trying to port to Android

  • 0

I’ve written a application in Java which I am trying to port to Android now, but for some reason when using the readLine() method from the BufferedReader it is returning null. I have tested the code in Java and it works fine no problem. The file I am reading from is a plain text file which I have put in with the rest of my java files. My code simple takes in user input for a login and upon clicking the login button checks the details by reading in the text file with the profiles in. Below is a simplication of my code:

OnClickListener in main activity:

button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            EditText textUsername = (EditText) findViewById(R.id.textUsername);
            EditText textPassword = (EditText) findViewById(R.id.textPassword);

            // Collect the login details entered by the user
            String username = textUsername.getText().toString();
            String password = textPassword.getText().toString();

            // Check if login details are correct
            LoginModel login = new LoginModel();
            Correct = login.isCorrect(username, password); // LINE COMMENTED
            // OUT SO THAT DETAILS DON'T NEED TO BE ENTERED

            //              Correct = true; // used to bypass login for now
            if (Correct) { // if details are correct then start main program
                Intent intent = new Intent (LoginView.this, MenuListView.class);
                startActivity(intent);
            }
            else System.out.println("Login is incorrect...");

        }
    });
}

The LoginModel.java class:

public LoginModel() {
    file = new File("Profiles");
    try {
        br = new BufferedReader(new FileReader(file));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Login Constructor successful!");
}

// Checks whether the inputted details are correct
public static boolean isCorrect(String u, String p) {
    System.out.println(p);
    boolean check = false;
    String line = null;
    try {
        do {
            line = br.readLine();   // This line is returning null
            // System.out.println("Checking profile : " + line);
            String[] info = line.split("\t");
            // nested if-statement to improve efficiency over &&
            if (info[0].equals(u)) {
                System.out.println("username found!");
                if (info[1].equals(p)) {
                    System.out.println("password correct!");
                    check = true;
                } else
                    System.out.println("password incorrect!");
            } else
                System.out.println("username not found!");
        } while (line != null && check == false);
    return check;

It is the br.readLine() which is returning null for some reason. I’ve looked it up and bufferedreader seems fully supported.

Edit: Ok, I’ve found out that it’s not actually finding the file but was probably trying to execute the isCorrect() method because it was static. I’ve removed the method and br declaration static tags now, and moved the profiles text file to the folder with all my java files in but it still can’t find it. How should I reference the position? What is the default position for android to look for the file if I simply reference it by name? Many thanks!

  • 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-27T20:33:23+00:00Added an answer on May 27, 2026 at 8:33 pm

    I am not sure if it is the actual cause of the NPE but it is definetly a bug:

    You are initializing br in your constructor, but you use it in isCorrect() which is static! It does not require an enclosing class of LoginModel in oreder to be invoked, so the c’tor might not be called at all before using br.

    You should initialize br when declaring it, or in a static scope, so it will be initialized when the class loads.

    EDIT: Note that it also indicates that br is declared static – so all instances of LogicModel actually use the same object of br!

    The reason why br.readLine() is returning null – might be you already exhausted the file in other calls to isCorrect(), or other methods which use br, but it will be impossible to know it for certain without more code.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.