I'm new to android and I am using this code from another stack overflow thread to make a little app so I can click thru some images using a next previous and restart button.
Changing ImageView on button click
unfortunately the app keeps crashing on startup.
I think its caused by java.lang.NullPointerException
I've googled and googled, but i'm too noob to fix it.
here is the code that im using
package com.example.android.boobies;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity implements View.OnClickListener {
    ImageView image = (ImageView) findViewById(R.id.boobiesOne);
    Button next;
    int a = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button restart = (Button) findViewById(R.id.restart);
        restart.setOnClickListener(this);
        Button previous = (Button) findViewById(R.id.previous);
        previous.setOnClickListener(this);
        next = (Button) findViewById(R.id.next);
        next.setOnClickListener(this);
    }
    @Override
    public void onClick(View view)
    {
        switch (view.getId())
        {
            case R.id.restart:
                image.setImageResource(R.drawable.image1);
                a = 0;
                break;
            case R.id.next:
                if (a == 0)
                {
                    image.setImageResource(R.drawable.image2);
                    a = 1;
                }
                else if (a == 1)
                {
                    image.setImageResource(R.drawable.image3);
                    a = 2;
                }
                else if (a == 2)
                {
                    image.setImageResource(R.drawable.image4);
                    a = 3;
                }
                else if (a == 3)
                {
                    image.setImageResource(R.drawable.image5);
                    a = 4;
                }
                else if (a == 4)
                {
                    image.setImageResource(R.drawable.image6);
                    a = 5;
                }
                else if (a == 5)
                {
                    image.setImageResource(R.drawable.image7);
                    a = 6;
                }
                else if (a == 6)
                {
                    image.setImageResource(R.drawable.image8);
                    a = 7;
                }
                else if (a == 7)
                {
                    image.setImageResource(R.drawable.image9);
                    image.setClickable(false);
                }
                break;
            case R.id.previous:
                a--;
                next.performClick();
                break;
        }
    }
}
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <ImageView
        android:id="@+id/boobiesOne"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scaleType="centerCrop"
        android:src="@drawable/image10" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:id="@+id/previous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onClick"
            android:text="previous" />
        <Button
            android:id="@+id/restart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onClick"
            android:text="restart" />
        <Button
            android:id="@+id/next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top|left"
            android:layout_weight="1"
            android:onClick="onClick"
            android:text="next" />
    </LinearLayout>
</LinearLayout>
 
    