Home>

java source

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button newCreate;
    private ListView listitem;
    private List<DtoItem>items;
    private static final String [] texts = {
            "abc", "bcd", "cde", "def", "efg",
            "fgh"
    };

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);
        newCreate = (Button) findViewById (R.id.button);
        newCreate.setOnClickListener (this);
        items = DaoItem.findAll (getApplicationContext ());
       // ListView listView = new ListView (this);
       // setContentView (listitem);
        ArrayAdapter<String>arrayAdapter =
                new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, texts);
        listitem.setAdapter (arrayAdapter);

xml source

<? xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns: android = "http://schemas.android.com/apk/res/android"
        xmlns: tools = "http://schemas.android.com/tools"
        xmlns: app = "http://schemas.android.com/apk/res-auto"
        android: layout_width = "match_parent"
        android: layout_height = "match_parent"
        tools: context = "com.example.minamigani.todolist.MainActivity" tools: layout_editor_absoluteY = "81dp"
        android: id = "@ + id/constrainlayout">

    <ListView
            android: id = "@ + id/todolistview"
            android: layout_width = "match_parent"
            android: layout_height = "match_parent"
            android: layout_weight = "1" tools: layout_editor_absoluteY = "100dp" tools: layout_editor_absoluteX = "60dp" />

    <LinearLayout
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: gravity = "center"
            android: visibility = "visible" tools: layout_editor_absoluteY = "464dp" tools: layout_editor_absoluteX = "0dp">
        <Button
                android: text = "@ string/NewCreate"
                android: layout_width = "wrap_content"
                android: layout_height = "47dp"
                android: id = "@ + id/button"
                app: layout_constraintStart_toStartOf = "parent"
                app: layout_constraintHorizontal_bias = "0.895" app: layout_constraintEnd_toEndOf = "parent"
                app: layout_constraintTop_toTopOf = "parent" app: layout_constraintBottom_toBottomOf = "parent"
                app: layout_constraintVertical_bias = "0.034" />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

Run it

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter (android.widget.ListAdapter)'


They said. What is different