1

My task: after button pressed, - second activity opening.
Problem: after button pressed, - "application closed unexpectedly".
LogCat said (short version):

04-10 21:25:24.968: E/AndroidRuntime(13032): java.lang.RuntimeException: Unable to start activity ComponentInfo{cat.dog.szosta/cat.dog.szosta.ListaOcenActivity}: java.lang.NullPointerException

LogCat said (full version):
https://drive.google.com/file/d/0B1jfkoUAwYVhYmFvSzBmS2ZIaU0/edit?usp=sharing

First activity code (partial):

private Button   mOcenyPrzycisk;
protected void onCreate(Bundle savedInstanceState) 
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.fragment_main);
  mOcenyPrzycisk = (Button)findViewById(R.id.ocenyPrzycisk);
  mOcenyPrzycisk.setOnClickListener(
    new View.OnClickListener() 
   {
      @Override
      public void onClick(View v) 
      {
       Intent intencja = new Intent(MainActivity.this, ListaOcenActivity.class); 
       startActivity(intencja);
      }
   }
                                   );
}

Second activity(partial):

        protected void onCreate(Bundle savedInstanceState) 
{
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_lista_ocen);

                mprzyciskWroc = (Button) findViewById(R.id.przyciskWroc);
    /*line 28*/ mprzyciskWroc.setOnClickListener(
                new    View.OnClickListener()
                      {
                        public void onClick (View v)
                        {
                            finish();
                        }
                      }
                                                );
}

P.S: second activity declared in AndroidManifest.xml

I was looking in (didn't help):
Using Intent in an Android application to show another activity
android intents
Thanks in advance!

Community
  • 1
  • 1
Pavlo Zvarych
  • 615
  • 2
  • 9
  • 13

3 Answers3

0

There is an exception in your second activity. (in ListaOcenActivity)

NullpointerException is thrown at line 28 of your ListaOcenActivity class, in the onCreate method. Search the method generating nullpointer exception, and handle it.

The way you are starting the activity is fine.

04-10 21:25:24.968: E/AndroidRuntime(13032): Caused by: java.lang.NullPointerException
04-10 21:25:24.968: E/AndroidRuntime(13032): at
cat.dog.szosta.ListaOcenActivity.onCreate(ListaOcenActivity.java:28) //here you can see its in your 2nd activity
Sipka
  • 2,291
  • 2
  • 27
  • 30
0

Problem is here: cat.dog.szosta.ListaOcenActivity.onCreate(ListaOcenActivity.java:28)

Paladine
  • 513
  • 3
  • 11
0

Looking at your LogCat (long version) it shows that the NPE is in class ListaOceanActivity line 28. Which means this code is correct. Look into that class instead.

sebgar
  • 194
  • 3
  • 7