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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:10:44+00:00 2026-06-13T19:10:44+00:00

Im trying to just create basic files internally for another app. So i wrote

  • 0

Im trying to just create basic files internally for another app. So i wrote a basic app to work out the kinks then was going to add it to the other app. Here is the log from the cat

10-09 17:56:14.579: D/dalvikvm(11092): Not late-enabling CheckJNI (already on)
10-09 17:56:15.599: E/Trace(11092): error opening trace file: No such file or directory (2)
10-09 17:56:16.549: D/gralloc_goldfish(11092): Emulator without GPU emulation detected.
10-09 17:57:20.158: D/dalvikvm(11092): Debugger has detached; object registry had 1 entries
10-09 17:57:30.078: E/Trace(11662): error opening trace file: No such file or directory (2)
10-09 17:57:30.759: D/gralloc_goldfish(11662): Emulator without GPU emulation detected.

The file is created. But when im implemented the code to create a file off the onClick it did not. Or when i put the file creating in a class other than the main class, it did not create the file.

here is my basic code:
`package com.newapp;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    newFile();

}
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    public String timeStamp(){
        Date myDate = new Date();
        return (DateFormat.getDateInstance().format(myDate) + " " +                         DateFormat.getTimeInstance().format(myDate));
    }

    public void newFile (){
         String FILENAME = timeStamp();
         String string = "hello world!";

         FileOutputStream fos = null;
            try {
        fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
            } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
                e.printStackTrace();
        }
         try {
                fos.write(string.getBytes());
            } catch (IOException e) {
                // TODO Auto-generated catch block
        e.printStackTrace();
        }
         try {
                    fos.close();
            } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}`

I got rid of the button and other classes for now. This is all the code other than the normal hello worlds screen they give you and an unmodified manifest.

EDIT
The code above works i and a file is created in /data/data/com.newapp/files
Just ran it again to make sure a file is created and got this from the cat.

10-09 17:57:29.482: D/dalvikvm(11662): Not late-enabling CheckJNI (already on)
10-09 17:57:30.078: E/Trace(11662): error opening trace file: No such file or directory (2)
10-09 17:57:30.759: D/gralloc_goldfish(11662): Emulator without GPU emulation detected.
10-09 18:53:35.238: D/dalvikvm(11662): Debugger has detached; object registry had 1 entries
10-09 18:53:53.389: E/Trace(14975): error opening trace file: No such file or directory (2)
10-09 18:53:54.658: I/Choreographer(14975): Skipped 36 frames! The application may be doing too much work on its main thread.
10-09 18:53:54.668: D/gralloc_goldfish(14975): Emulator without GPU emulation detected.

I am going to move it to its own class now and try it.

Here is the file creation in its own class:
package com.newapp;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;    
import java.util.Date;

import android.app.Activity;
import android.content.Context;

public class NewFile extends Activity {

public String timeStamp(){
    Date myDate = new Date();
    return (DateFormat.getDateInstance().format(myDate) + " " +             DateFormat.getTimeInstance().format(myDate));
}

public NewFile (){
     String FILENAME = timeStamp();
     String string = "hello world!";

     FileOutputStream fos = null;
    try {
        fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     try {
        fos.write(string.getBytes());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     try {
        fos.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }
 }

And here is the Main activity:

package com.newapp;



import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;


public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    NewFile firstone = new NewFile();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}   
}

Finally I tried it a few different ways with having the NewFile(); as a constructor as just a regular method and calling firstone.newFile();
Having a lot of trouble it will not even run on the virtual device or tablet right now.

  • 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-13T19:10:45+00:00Added an answer on June 13, 2026 at 7:10 pm

    I figured out the problem with the help of a friend.
    You cannot “extend activity” in the new class.
    You need to use context to reference the class. The final code for the NewFile class is:

    package com.newapp;
    
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.util.Date;
    import android.content.Context;
    
    public class NewFile{
    
    public String timeStamp(){
        Date myDate = new Date();
        return (DateFormat.getDateInstance().format(myDate) + " " + DateFormat.getTimeInstance().format(myDate));
    }
    
    public void createFile(Context c) throws IOException{
         String FILENAME = timeStamp();
         String string = "hello world!";
    
         FileOutputStream fos = c.openFileOutput(FILENAME, Context.MODE_PRIVATE);
        fos.write(string.getBytes());
        fos.close();
    
    
    }
    }
    

    and in the main class you just needed to call:

    NewFile firstfile = new NewFile();
    firstfile.createFile(getBaseContext());
    

    In the onCreate method.

    Thanks

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

Sidebar

Related Questions

I am trying to just create a basic layout, but i am having trouble
Trying to create a facebook app just to learn and coming across a strange
trying to just create a simple OpenXML document based on http://www.codeproject.com/Articles/371203/Creating-basic-Excel-workbook-with-Open-XML i moved it
i am just trying to create a link which execute some JavaScript in stead
I am just trying to create a file with QProcess by the following source
This is driving me wild with frustration. I am just trying to create a
I'm not looking to harvest information, I'm just trying to create a way to
I am trying to create a little ajax chat system (just for the heck
Right now I'm trying to create my own tiny MVC (just for practice and
I'm trying to create a Custom Part that just drops text into the page.

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.