Haveing a created directory and file be recognized globally
<p>How do I get other activities to recognize a directory and its files? If I try to refer to them by name in other activities or even functions the code will not compile. I do not want to make copies of the directory or its files and thus I do not want to just the file path. Do I need to include this stuff in the assets or rescources tree? If so how do I do that? I now declare the directory outside the oncreate function and try to use an instance of the activity with the file in the other activity so it can access the file as a member. This does not work as I get an exception. I have Included the code for the other activity below.</p>

<pre><code>//outside oncreate

public File newdir=null;

// inside oncreate

File sdc=Environment.getExternalStorageDirectory();

    String faceplace = "faceplace";

     newdir = new File(sdc,faceplace);  

    if (!newdir.exists())
    {

        newdir.mkdirs();
    }


    Random generator = new Random(); 
    int n = 10000; 
    n = generator.nextInt(n); 
    String facename = "face" + n + ".jpg";

    File picfile = new File (newdir,facename);
</code></pre>

<p>Here is the code for the activity which I am trying to get to recognize newdir. If I just use the variable it says it cannot resolve it. If I try to make an instance of the previous class, which I do below, the activity will not start. The debugger says "Unable to start activity ComponentInfo{senior.sem/senior.sem.facerec}: java.lang.NullPointerException."</p>

<pre><code> public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facerec);

     ImageView imageView2 = (ImageView)findViewById(R.id.imageView2);


 PicturetakerActivity pictake = new PicturetakerActivity();



File newdir = pictake.newdir;
File[] farray = newdir.listFiles();


int size =farray.length;

 Bitmap[] gallery= new Bitmap[size];



for (int i = 0; i &lt; size; i++)
{

     try { 

         FileInputStream in = new FileInputStream(farray[i]); 

         Bitmap face = null;

         face = BitmapFactory.decodeFile(farray[i].getAbsolutePath());

         gallery[i]=face;

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

    imageView2.setImageBitmap(gallery[i]);

}






}
</code></pre>

<p>}</p>
