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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:08:30+00:00 2026-05-29T12:08:30+00:00

The following method shows NullPointerException. I can’t understand what is wrong with below code.

  • 0

The following method shows NullPointerException. I can’t understand what is wrong with below code. Where the file stored in

public class Mtx extends Activity  {
public void ConfWrite() {
    try {
     BufferedWriter buf = new BufferedWriter(new FileWriter(getFilesDir()+"\\file.java"));

        buf.write("Hello Android");
        buf.newLine();
        buf.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}   

}

stack trace output

02-10 13:11:18.365: WARN/System.err(7179): java.lang.NullPointerException
02-10 13:11:18.396: WARN/System.err(7179):     at android.content.ContextWrapper.getFilesDir(ContextWrapper.java:178)
02-10 13:11:18.419: WARN/System.err(7179):     at mediatronix.HAT.Mtx.ConfWrite(Mtx.java:19)
02-10 13:11:18.425: WARN/System.err(7179):     at mediatronix.HAT.MainMenu.onCreate(MainMenu.java:46)
02-10 13:11:18.437: WARN/System.err(7179):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-10 13:11:18.485: WARN/System.err(7179):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-10 13:11:18.495: WARN/System.err(7179):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-10 13:11:18.505: WARN/System.err(7179):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-10 13:11:18.525: WARN/System.err(7179):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-10 13:11:18.545: WARN/System.err(7179):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 13:11:18.555: WARN/System.err(7179):     at android.os.Looper.loop(Looper.java:123)
02-10 13:11:18.585: WARN/System.err(7179):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-10 13:11:18.616: WARN/System.err(7179):     at java.lang.reflect.Method.invokeNative(Native Method)
02-10 13:11:18.625: WARN/System.err(7179):     at java.lang.reflect.Method.invoke(Method.java:521)
02-10 13:11:18.665: WARN/System.err(7179):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-10 13:11:18.675: WARN/System.err(7179):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-10 13:11:18.695: WARN/System.err(7179):     at dalvik.system.NativeStart.main(Native Method)

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-29T12:08:30+00:00Added an answer on May 29, 2026 at 12:08 pm

    Instead of this:

    getFilesDir()+"file.java"
    

    try this:

    new File(getFilesDir(), "file.java")
    

    Or better yet,

    new BufferedWriter(new OutputStreamWriter(
        openFileOutput("file.java", MODE_PRIVATE)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following method, based on code in this question , shows a file download
My question related to the following 3 code excerpt: code of class method: start(options
can someone please show me documentation on this method? i have the following line:
Why does the following method hang? public void pipe(Reader in, Writer out) { CharBuffer
Consider the following method signatures: public fooMethod (Foo[] foos) { /*...*/ } and public
I am trying to use the code shown in the following example: java.lang.NullPointerException while
i tried the following code for cloning the object. while compiling it shows clone
I have the following class: public class Product { public virtual Guid Id {
I have something similar to the following method: public ActionResult Details(int id) { var
The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public

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.