Break activity classes into multiple files
<blockquote>
  <p>This is the main activity
  I am trying to move like classes to a new file
  Once I do, I am not able to successfully call the class
  The following code generates a null pointer, though the pointer is not null
  I cannot simply change the savedTrainInfo class to static because
  then the file routines will not work.  There must be a simple solution
  I need to keep my classes separate for clarity.</p>
</blockquote>

<pre><code>import mp.trains.conductor.savedTrainInfo;
public class trains extends Activity 
  {
  private savedTrainInfo msavedTrainInfo;
  protected static Context context;

  public void onCreate(Bundle savedInstanceState) 
    {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    trains.context=getApplicationContext();  
    msavedTrainInfo=new savedTrainInfo();
    msavedTrainInfo.getTrainAttributes();
    }
  }
</code></pre>

<blockquote>
  <p>new file
  many functions here; mainly file I/O
  These all work fine if there are located in the main activity trains
  You are correct.  The error seems to be in if (readStartupFile(trainAttributes)==false)</p>
</blockquote>

<pre><code>public class savedTrainInfo extends trains
  {
  public void getTrainAttributes()
    {
    trainAttributes=new String [10];
if (readStartupFile(trainAttributes)==false)
  {
  fileLine=0;
  }
else
  {
  try 
    {
    fileLine = Integer.parseInt(trainAttributes[0].toString());
    } 
  catch(NumberFormatException nfe) 
    {
    System.out.println("Could not parse " + nfe);
    } 
  }
    }

  public  boolean readStartupFile(String objects[])
    {
    try 
    {
// InputStream fHandle = openFileInput("startupTrains.txt");
InputStream fHandle = trains.context.openFileInput("startupTrains.txt");
if (fHandle != null) 
  {
  // prepare the file for reading
  InputStreamReader inputreader = new InputStreamReader(fHandle);
  BufferedReader buffreader = new BufferedReader(inputreader);
  String line;
  line = buffreader.readLine();
  if (line == null)
    {
    fHandle.close();
    return false;
    }
  else
    {
    String[] item = (line).split(",");                  
    objects[0]=item[0].toString();                      
    fHandle.close();
    }
  return true;
  }
else
  {
  return false;
  }
}
catch (FileNotFoundException e2) 
  {
  return false;
  } 
catch (IOException e) 
{
e.printStackTrace();
return false;
}
}

  }
</code></pre>
