1

Why am I getting that error? It's causing my app to crash. Every time I test my app on my device the logcat puts out that error and I don't know why. I have a reasonable understanding of what a null pointer exception is and I have search thoroughly for an issue similar to mine. I have tried to reformat the click listener in several ways, made sure I have the correct view ID etc. Here is my code.

public class GridActivity extends AppCompatActivity {

Button dijkstra;
Button astar;
GridView grid;
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid);
    dijkstra = findViewById(R.id.dijkstra);
    astar = astar.findViewById(R.id.astar);
    grid = astar.findViewById(R.id.grid);







    dijkstra.setOnClickListener(new View.OnClickListener( ) {
        @Override
        public void onClick(View v) {


            GridViewe geoView = new GridViewe(GridActivity.this);
            geoView.Dijkstra( );
        }
    });
    astar.setOnClickListener(new View.OnClickListener( ) {

        @Override
        public void onClick(View v) {


            GridViewe geoView = new GridViewe(GridActivity.this);
            geoView.Astar( );

        }
    });


}

public void setContentView(int activity_grid) {
}

@Override
public void onStop() {
    GridViewe geoView = new GridViewe(GridActivity.this);

    if(geoView.dijkstrathread.getStatus()== AsyncTask.Status.RUNNING)
       geoView.dijkstrathread.cancel(true);
    if(geoView.astarthread.getStatus()==AsyncTask.Status.RUNNING){
        geoView.astarthread.cancel(true);
    }

    super.onStop();
}

}

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".GridActivity">

<GridView
    android:id="@+id/grid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

/>

<Button
    android:id="@+id/dijkstra"
    android:layout_width="63dp"
    android:layout_height="35dp"
    android:layout_weight="1"
    android:text="DIJKSTRA"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<Button
    android:id="@+id/astar"
    android:layout_width="106dp"
    android:layout_height="27dp"
    android:layout_weight="1"
    android:text="A* (A star)"
    tools:layout_editor_absoluteX="168dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

K will
  • 19
  • 2

0 Answers0