3 Replies - 1865 Views - Last Post: 25 October 2012 - 06:37 AM

#1 slehmann101  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 146
  • Joined: 30-November 11

File not found exception

Posted 16 October 2012 - 05:44 PM

I am trying to create a text file and access it from another class
here is the logcat
10-17 00:41:26.391: W/System.err(408): java.io.FileNotFoundException: /user_info.txt (No such file or directory)
10-17 00:41:26.401: W/System.err(408): 	at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
10-17 00:41:26.401: W/System.err(408): 	at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
10-17 00:41:26.401: W/System.err(408): 	at java.io.FileInputStream.<init>(FileInputStream.java:82)
10-17 00:41:26.412: W/System.err(408): 	at java.io.FileInputStream.<init>(FileInputStream.java:134)
10-17 00:41:26.412: W/System.err(408): 	at com.slehmann.volumetimechanger.AlarmReceiver.onReceive(AlarmReceiver.java:24)
10-17 00:41:26.412: W/System.err(408): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
10-17 00:41:26.412: W/System.err(408): 	at android.app.ActivityThread.access$3200(ActivityThread.java:125)
10-17 00:41:26.412: W/System.err(408): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
10-17 00:41:26.421: W/System.err(408): 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 00:41:26.421: W/System.err(408): 	at android.os.Looper.loop(Looper.java:123)
10-17 00:41:26.421: W/System.err(408): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
10-17 00:41:26.431: W/System.err(408): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-17 00:41:26.431: W/System.err(408): 	at java.lang.reflect.Method.invoke(Method.java:521)
10-17 00:41:26.431: W/System.err(408): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-17 00:41:26.431: W/System.err(408): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-17 00:41:26.431: W/System.err(408): 	at dalvik.system.NativeStart.main(Native Method)
10-17 00:41:26.431: W/System.err(408): java.lang.NullPointerException
10-17 00:41:26.431: W/System.err(408): 	at com.slehmann.volumetimechanger.AlarmReceiver.onReceive(AlarmReceiver.java:49)
10-17 00:41:26.431: W/System.err(408): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
10-17 00:41:26.431: W/System.err(408): 	at android.app.ActivityThread.access$3200(ActivityThread.java:125)
10-17 00:41:26.441: W/System.err(408): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
10-17 00:41:26.441: W/System.err(408): 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 00:41:26.441: W/System.err(408): 	at android.os.Looper.loop(Looper.java:123)
10-17 00:41:26.441: W/System.err(408): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
10-17 00:41:26.441: W/System.err(408): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-17 00:41:26.471: W/System.err(408): 	at java.lang.reflect.Method.invoke(Method.java:521)
10-17 00:41:26.471: W/System.err(408): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-17 00:41:26.471: W/System.err(408): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-17 00:41:26.471: W/System.err(408): 	at dalvik.system.NativeStart.main(Native Method)
10-17 00:41:26.492: W/System.err(408): java.lang.NullPointerException
10-17 00:41:26.492: W/System.err(408): 	at com.slehmann.volumetimechanger.AlarmReceiver.onReceive(AlarmReceiver.java:49)
10-17 00:41:26.501: W/System.err(408): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
10-17 00:41:26.501: W/System.err(408): 	at android.app.ActivityThread.access$3200(ActivityThread.java:125)
10-17 00:41:26.501: W/System.err(408): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
10-17 00:41:26.511: W/System.err(408): 	at android.os.Handler.dispatchMessage(Handler.java:99)
10-17 00:41:26.511: W/System.err(408): 	at android.os.Looper.loop(Looper.java:123)
10-17 00:41:26.511: W/System.err(408): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
10-17 00:41:26.511: W/System.err(408): 	at java.lang.reflect.Method.invokeNative(Native Method)
10-17 00:41:26.511: W/System.err(408): 	at java.lang.reflect.Method.invoke(Method.java:521)
10-17 00:41:26.511: W/System.err(408): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-17 00:41:26.511: W/System.err(408): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-17 00:41:26.511: W/System.err(408): 	at dalvik.system.NativeStart.main(Native Method)


I believe that the nullPointer is caused because of the file not found.

Here is my first class
 FileOutputStream fos;
		        OutputStreamWriter osw;
		        try 
		        {
		        	FileWriter f = new FileWriter("/sdcard/download/possible.txt");
		            fos = openFileOutput("user_info.txt", Context.MODE_WORLD_WRITEABLE);
		            osw = new OutputStreamWriter(fos);
		            osw.write("type"+type+"year"+year+"month"+month+"day"+day+"minute"+minute+"hour"+hour);
		            osw.close();
		            fos.close();
		         
		     
		        } catch (Exception e) {
		            // TODO Auto-generated catch block
		            e.printStackTrace();
		        
		        }
	 cal = Calendar.getInstance();
				 cal.set(year, month, day, hour,minute); 
				 intent = new Intent(this, AlarmReceiver.class);

and here is my second
package com.slehmann.volumetimechanger;
 
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import android.media.AudioManager;
import android.os.Bundle;
 
public class AlarmReceiver extends BroadcastReceiver {
 
 @Override
 public void onReceive(Context context, Intent intent) {
	 
	 try 
     {
		 FileInputStream fis = new FileInputStream("user_info.txt");
         //FileInputStream fis =openFileInput("user_info.txt");
         InputStreamReader isr = new InputStreamReader(fis);
         BufferedReader buff = new BufferedReader(isr);
         String line;
         while((line = buff.readLine()) != null)
         {

           Log.v("",line);
         }
     } 
     catch (FileNotFoundException e) 
     {
         // TODO Auto-generated catch block
         e.printStackTrace();
     } 
     catch (IOException e) 
     {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }

How can I remedy these errors?

This post has been edited by slehmann101: 16 October 2012 - 05:45 PM


Is This A Good Question/Topic? 0
  • +

Replies To: File not found exception

#2 H3R3T1C  Icon User is offline

  • Android Expert
  • member icon

Reputation: 277
  • View blog
  • Posts: 757
  • Joined: 30-March 07

Re: File not found exception

Posted 16 October 2012 - 07:05 PM

Are you trying to save the file to sdcard?
Was This Post Helpful? 0
  • +
  • -

#3 slehmann101  Icon User is offline

  • D.I.C Head

Reputation: 21
  • View blog
  • Posts: 146
  • Joined: 30-November 11

Re: File not found exception

Posted 17 October 2012 - 03:20 PM

yes
Was This Post Helpful? 0
  • +
  • -

#4 Nerfpl  Icon User is offline

  • D.I.C Head

Reputation: 43
  • View blog
  • Posts: 165
  • Joined: 15-January 12

Re: File not found exception

Posted 25 October 2012 - 06:37 AM

Check Data Storage section. Your errors says file is not found so that's it. Either is not there or you point to it incorrectly

This post has been edited by Nerfpl: 25 October 2012 - 06:37 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1