title: Creating global class. Error: android.app.application can not be cast to com
body: <p>I'm trying to create a global class. I want have a global variable for all my activity.</p>
  
  <p>My class:</p>
  
  <pre><code>package com.example.app;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.io.FileWriter;
  import java.io.IOException;
  
  import android.app.Application;
  
  public class Records extends Application{
  
  private int N_livelli=30;
  private int[] record = new int[N_livelli];
  private String path = getApplicationContext().getFilesDir().getPath() + "/Records.txt";
  
  public void LetturaFile()
  {
      File f = new File(path);
      if(f.exists())
      {
          try
          {
              FileReader fileLeggi = new FileReader(path);
              BufferedReader lettore = new BufferedReader(fileLeggi);
              String rigaLetta;
              int n=0;
              while((rigaLetta=lettore.readLine())!=null)
              {
                  record[n]=Integer.valueOf(rigaLetta);
                  n++;
              }
              lettore.close();
              fileLeggi.close();
          }
          catch (IOException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
      else
      {
          try 
          {
              for(int i=0;i&lt;N_livelli;i++) record[i]=0;
              f.createNewFile();
              FileWriter fileScrivi = new FileWriter(path);
              fileScrivi.write("");
              for(int i=0;i&lt;N_livelli;i++) fileScrivi.append(record[i]+"\n");
              fileScrivi.close();
          }
          catch (IOException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  
  public int getRecord(int livello)
  {
      return record[livello-1];
  }
  }
  </code></pre>
  
  <p>My code on OnCreate of MainActivity:</p>
  
  <pre><code>[...]
  Records records = (Records) getApplicationContext();
  records.LetturaFile();
  [..]
  </code></pre>
  
  <p>My AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.app"
  android:versionCode="3"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="9"
      android:targetSdkVersion="21" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
  
      &lt;activity
          android:name=".MainActivity"
          [...]
      &lt;/activity&gt;
      &lt;activity
          android:name=".SecondActivity"
          [...]
      &lt;/activity&gt;
   &lt;/application&gt;
   &lt;application 
      android:name=".Records"&gt;
   &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Eclipse error: android.app.application can not be cast to com.example.app.Records</p>
  
  <p>Please help me. Thank you.</p>