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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:01:13+00:00 2026-06-12T10:01:13+00:00

I am trying to set text in EditText by reading a file but app

  • 0

I am trying to set text in EditText by reading a file but app get closed every time. Can someone tell what’s wrong with this code?

package com.example;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.*;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class EditNoteActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        String FILENAME = "note_file";
        EditText text = (EditText) findViewById(R.id.editText1);
        byte[] buffer = new byte[100];


        super.onCreate(savedInstanceState);
        setContentView(R.layout.editnote);

        //Intent intent = getIntent();

        FileInputStream fos = null;
        try {
            fos = openFileInput(FILENAME);
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        assert fos != null;
        try {
            fos.read(buffer, 0, 10);
            String str = buffer.toString();
            text.setTextSize(48);
            text.setText(str);
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
    public void onClickSave(View theButton) {
        //Intent intent = new Intent(this, MyActivity.class);
        //startActivity(intent);
        String FILENAME = "note_file";

        EditText text = (EditText) findViewById(R.id.editText1);


        FileOutputStream fos = null;
        try {
            fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        assert fos != null;
        try {
            fos.write(text.getText().toString().getBytes());
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        finish();
    }
    public void onClickBack(View theButton) {
        //Intent intent = new Intent(this, MyActivity.class);
        //startActivity(intent);
        finish();
    }
}

I tried to edit this to remove irrelevant code but I got error, “Your post does not have much context to explain the code sections; please explain your scenario more clearly.”. Unfortunately there is not much and anyway this question has been answered.

  • 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-06-12T10:01:15+00:00Added an answer on June 12, 2026 at 10:01 am

    You are initializing EditText (text) before setting content view, so that the EditText object is null while finding edit text by id, that’s why application crashed.

    Modify your code as follows

    super.onCreate(savedInstanceState);
    setContentView(R.layout.editnote);
    
    String FILENAME = "note_file";
    EditText text = (EditText) findViewById(R.id.editText1);
    byte[] buffer = new byte[100];
    

    FYI: while asking questions, post error log too then only you can get quick and proper answers.

    Update

    Refer :
    to get error log from eclipse

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

Sidebar

Related Questions

I'm trying get the text from an EditText but i've logged out the EditText
I am trying to get an int from an edit text set to inputType=number
i am trying to get the text input/values from an EditText widget as its
When I am trying to display a text in EditText using setText() method the
I am trying to set some text on a label descriptionLabel.text = [NSString stringWithFormat:mySTUser.bio];
I am trying to set focus on a hidden text box. I want that
I'm trying to set the focus on a text input element using document.getElementById( 'id'
I'm trying to set together a simple TextBox with some watermark text in the
I am trying to implement a full text for set of models. I heard
I am trying to figure out how to set the value of the text

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.