0

In my simple app I'm getting this error message:

FATAL EXCEPTION: main
              Process: com.example.grudzio.helloworld, PID: 31274
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.grudzio.helloworld/com.example.grudzio.helloworld.DiaryActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2750)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2811)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6316)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
               Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                  at com.example.grudzio.helloworld.DiaryActivity.onCreate(DiaryActivity.java:28)
                  at android.app.Activity.performCreate(Activity.java:6757)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2703)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2811) 
                  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:154) 
                  at android.app.ActivityThread.main(ActivityThread.java:6316) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 

I think the problem is in that file, but I can't detect it:

package com.example.grudzio.helloworld;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.util.ArrayList;

public class DiaryActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_diary);

    ArrayList<wpisDiary> logs = new ArrayList<wpisDiary>();

    logs.add(new wpisDiary("date","time","log"));
    logs.add(new wpisDiary("date1","time1","log1"));
    logs.add(new wpisDiary("date2","time2","log2"));
    logs.add(new wpisDiary("date3","time3","log3"));




    LogAdapter adapter=new LogAdapter(this,logs);

    ListView listView=(ListView) findViewById(R.id.list_log);

    listView.setAdapter(adapter);

}
}

I'd like to make a list in another activity. But the app crashes when I press a button to go to that activity. If it is needed I can add more code from other files. Thanks for help :)

wolnio
  • 103
  • 1
  • 8

0 Answers0