title: How to show toast in second java file?
body: <p>I have been reading this forum for days and I have found no answer to my problem.</p>
  
  <p>I'm having problem with getting java.lang.NullPointerException when I try to show Toast.</p>
  
  <p>In my android application I have MyWorkActivity.java which is main activity and Statistika.java intended to calculate some statistics based on data from my database.</p>
  
  <p>Inside class MyWorkActivity (public class MyWorkActivity extends Activity implements OnClickListener) i have menu item statistika.</p>
  
  <p>When I press on that item I want to show layout Statistika.xml with data from statistika.java like this:</p>
  
  <pre><code>public class MyWorkActivity extends Activity implements OnClickListener 
  {
      //Menu item statistika
      else if(item.getItemId()==R.id.statistika)
      {
          //Layout statistika.xml
           setContentView(R.layout.statistika);
  
           Statistika nova_statistika = new Statistika();
           nova_statistika.rsatiDanasJuceMjesec(sDatumZaPrikaz);
      }
  }
  </code></pre>
  
  <p>But I have been receiving java.lang.NullPointerException on <code>dbJuceDanas = this.openOrCreateDatabase(DatabaseInfo.IME_BAZE, MODE_PRIVATE,null);</code> so I have commented database part and tried only Toast but I still get java.lang.NullPointerException.</p>
  
  <p>This is my Statistika.java:</p>
  
  <pre><code>public class Statistika extends Activity
  {
   public void rsatiDanasJuceMjesec (String sDatumZaRacunanje)
     {
        Toast.makeText(getBaseContext(), "Toast is working! ", Toast.LENGTH_LONG).show();
  
      //Računanje radnih sati za prikazani dan
  //      SQLiteDatabase dbJuceDanas = null;
  //      dbJuceDanas = this.openOrCreateDatabase(DatabaseInfo.IME_BAZE, MODE_PRIVATE,null);
  //          
  //      //Filtriranje rekordseta po datumu
  //      Cursor cJuceDanas = dbJuceDanas.rawQuery("SELECT * FROM " + DatabaseInfo.IME_TABELE + " WHERE " + DatabaseInfo.DATUM + " LIKE '%" + MyWorkActivity.sDatumZaPrikaz + "'", null);
  //      
  //      if (cJuceDanas !=null &amp;&amp; cJuceDanas.getCount() &gt; 0) 
  //      {
  //          //Ako postoje upisi za datum trenutnog upisa
  //          int Column4 = cJuceDanas.getColumnIndex("r_vrijeme");
  //
  //          //Sumiranje svih radnih vremena od danas
  //          fRVDanas=Float.valueOf(0);
  //          do 
  //          {
  //              cJuceDanas.moveToFirst();
  //              fRVDanas=fRVDanas+cJuceDanas.getFloat(Column4);
  //          
  //          }while (cJuceDanas.moveToNext());
  //      }
      }
  }
  </code></pre>
  
  <p>This is LogCat:</p>
  
  <pre><code>04-25 12:33:15.020: E/AndroidRuntime(927): FATAL EXCEPTION: main
  04-25 12:33:15.020: E/AndroidRuntime(927): java.lang.NullPointerException
  04-25 12:33:15.020: E/AndroidRuntime(927):  at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
  04-25 12:33:15.020: E/AndroidRuntime(927):  at android.widget.Toast.&lt;init&gt;(Toast.java:89)
  04-25 12:33:15.020: E/AndroidRuntime(927):  at android.widget.Toast.makeText(Toast.java:231)
  04-25 12:33:15.020: E/AndroidRuntime(927):  at myWork.amicus.ba.Statistika.rsatiDanasJuceMjesec(Statistika.java:69)
  04-25 12:33:15.020: E/AndroidRuntime(927):  at myWork.amicus.ba.MyWorkActivity.onOptionsItemSelected(MyWorkActivity.java:3028)
  04-25 12:33:15.020: E/AndroidRuntime(927):  at android.app.Activity.onMenuItemSelected(Activity.java:2205)
  04-25 12:33:15.020: E/AndroidRuntime(927):  at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:748)
  </code></pre>
  
  <p>I have tried following:</p>
  
  <pre><code>Toast.makeText(this, "Toast is working! ", Toast.LENGTH_LONG).show();
  
  Toast.makeText(Statistika.this, "Toast is working! ", Toast.LENGTH_LONG).show();
  </code></pre>
  
  <p>and many other combinations but it doesn't work.</p>
  
  <p>As I can understand, problem is with context.</p>
  
  <p>What do I need to do to be able to show Toast message and access database from Statistika.java?</p>