getSelectedItem().toString() returning null value
<p><strong>----------UPDATE------------</strong></p>

<p>The part where i run the query is</p>

<pre><code>public class DatabaseAccess extends MainActivity{
    private SQLiteOpenHelper openHelper;
    private SQLiteDatabase database;
    private static DatabaseAccess instance;


    private String courseValue = " course = " + getCourseValue();
    private String hungerValue = " hungerLevel = " + getHungerValue();
    private String prepValue = " preparationTime " + getPrepValue();
    private String cuisineValue = " cuisine = " + getCuisineValue();

    /**
     * Private constructor to avoid object creation from outside classes.
     *
     * @param context
     */
    private DatabaseAccess(Context context) {
        this.openHelper = new DatabaseOpenHelper(context);
    }

    /**
     * Return a singleton instance of DatabaseAccess.
     *
     * @param context the Context
     * @return the instance of DabaseAccess
     */
    public static DatabaseAccess getInstance(Context context) {
        if (instance == null) {
            instance = new DatabaseAccess(context);
        }
        return instance;
    }

    /**
     * Open the database connection.
     */
    public void open() {
        this.database = openHelper.getWritableDatabase();
    }

    /**
     * Close the database connection.
     */
    public void close() {
        if (database != null) {
            this.database.close();
        }
    }

    /**
     * Read all quotes from the database.
     *
     * @return a List of quotes
     */
    public List&lt;String&gt; getResults() {
        List&lt;String&gt; list = new ArrayList&lt;&gt;();
        Cursor cursor = database.rawQuery("SELECT foodName FROM foodDB where" + cuisineValue +" &amp;" + hungerValue +" &amp;"+ prepValue +" &amp;"+ courseValue, null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            list.add(cursor.getString(0));
            cursor.moveToNext();
        }
        cursor.close();
        return list;
    }

}
</code></pre>

<p>I am creating an app in Android Studio where I want to get the value of a spinner and assign it to a variable. However, the app always crashes during testing and shows:</p>

<pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{
    com.example.rcadit.foodgenie/com.example.rcadit.foodgenie.resultActivity}:
    android.database.sqlite.SQLiteException: near "null":
    syntax error (code 1): , while compiling:
    SELECT foodName FROM foodDB where cuisine = null 
            &amp; hungerLevel = null &amp; preparationTime null &amp; course = null
</code></pre>

<p>And this is my <code>mainActivity.java</code>:</p>

<pre><code>package com.example.rcadit.foodgenie;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                           int pos, long id) {
    // An item was selected. You can retrieve the selected item using
    parent.getItemAtPosition(pos);
}

public void onNothingSelected(AdapterView&lt;?&gt; parent) {
    // Another interface callback
}

Toolbar toolbar;
@InjectView(R.id.salty)
SeekBar salty;
private String hungerValue;
private String cuisineValue;
private String prepValue;
private String courseValue;

public void go(View view) {
    Intent intent = new Intent(this, resultActivity.class);
    startActivity(intent);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.inject(this);
    initToolBar();
    saltySlider();
    spicySlider();
    sweetSlider();

    Spinner hunger_spinner = (Spinner) findViewById(R.id.hunger_spinner);
        // Create an ArrayAdapter using the string array and a default spinner layout
        ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this,
            R.array.hunger_level, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
         hunger_spinner.setAdapter(adapter);

    Spinner cuisine_spinner = (Spinner) findViewById(R.id.cuisine_spinner);
        // Create an ArrayAdapter using the string array and a default spinner layout
         ArrayAdapter&lt;CharSequence&gt; adapter2 = ArrayAdapter.createFromResource(this,
                 R.array.cuisine, android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        cuisine_spinner.setAdapter(adapter2);

    Spinner prep_spinner = (Spinner) findViewById(R.id.time_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter&lt;CharSequence&gt; adapter3 = ArrayAdapter.createFromResource(this,
            R.array.preparation_time, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
    prep_spinner.setAdapter(adapter3);

    Spinner course_spinner = (Spinner) findViewById(R.id.course_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter&lt;CharSequence&gt; adapter4 = ArrayAdapter.createFromResource(this,
            R.array.course, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
    course_spinner.setAdapter(adapter4);

    //give data to variables
    hungerValue = hunger_spinner.getSelectedItem().toString();
    if (hungerValue.equals("Low") ) {
        hungerValue = "1";
    }
    if (hungerValue.equals("Medium") ) {
        hungerValue = "2";
    }
    if (hungerValue.equals("High") ) {
        hungerValue = "3";
    }
    cuisineValue = cuisine_spinner.getSelectedItem().toString();
    prepValue = prep_spinner.getSelectedItem().toString();
    if (prepValue.equals("Under 10 mins") ) {
        prepValue = "&lt; 10";
    }
    if (prepValue.equals("No Preparation") ) {
        prepValue = " = 0";
    }
    if (prepValue.equals("Under 20 mins") ) {
        prepValue = "&lt; 20";
    }
    if (prepValue.equals("Under 30 mins") ) {
        prepValue = "&lt; 30";
    }
    if (prepValue.equals("Over 30 mins") ) {
        prepValue = "&gt; 30";
    }
    courseValue = course_spinner.getSelectedItem().toString();
}

// (...) getters and setter for hungerValue, cuisineValue, prepValue, courseValue

private void saltySlider() {
    salty.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int progressChanged = 0;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progressChanged = progress * 50;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (progressChanged &lt; 100 / 3) {
                TextView textView = (TextView) findViewById(R.id.howSalty);
                textView.setHint("Not Salty");

            }
            if (progressChanged &gt; 100 / 3 &amp; progressChanged &lt; 2 * (100 / 3)) {
                TextView textView = (TextView) findViewById(R.id.howSalty);
                textView.setHint("Salty");
            }
            if (progressChanged &gt; 2 * (100 / 3)) {
                TextView textView = (TextView) findViewById(R.id.howSalty);
                textView.setHint("Very Salty");
            }
        }
    });
}

private void sweetSlider() {
    SeekBar sweet = (SeekBar) findViewById(R.id.sweet);
    sweet.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int progressChanged = 0;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progressChanged = progress * 50;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (progressChanged &lt; 100 / 3) {
                TextView textView = (TextView) findViewById(R.id.howSweet);
                textView.setHint("Not Sweet");

            }
            if (progressChanged &gt; 100 / 3 &amp; progressChanged &lt; 2 * (100 / 3)) {
                TextView textView = (TextView) findViewById(R.id.howSweet);
                textView.setHint("Sweet");
            }
            if (progressChanged &gt; 2 * (100 / 3)) {
                TextView textView = (TextView) findViewById(R.id.howSweet);
                textView.setHint("Very Sweet");
            }
        }
    });
}

private void spicySlider() {
    SeekBar spicy = (SeekBar) findViewById(R.id.spicy);
    spicy.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int progressChanged = 0;

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            progressChanged = progress * 50;
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            if (progressChanged &lt; 100 / 3) {
                TextView textView = (TextView) findViewById(R.id.howSpicy);
                textView.setHint("Not Spicy");

            }
            if (progressChanged &gt; 100 / 3 &amp; progressChanged &lt; 2 * (100 / 3)) {
                TextView textView = (TextView) findViewById(R.id.howSpicy);
                textView.setHint("Spicy");
            }
            if (progressChanged &gt; 2 * (100 / 3)) {
                TextView textView = (TextView) findViewById(R.id.howSpicy);
                textView.setHint("Very Spicy");
            }
        }
    });
}

public void initToolBar() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    setSupportActionBar(toolbar);
}
}
</code></pre>

<p>And this is my full log file:</p>

<pre><code>07/29 15:49:54: Launching app
Cold swapped changes.
$ adb shell am start -n "com.example.rcadit.foodgenie/com.example.rcadit.foodgenie.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 3218 on device Nexus_5_API_23_x86 [emulator-5554]
W/System: ClassLoader referenced unknown path: /data/app/com.example.rcadit.foodgenie-1/lib/x86
W/System: ClassLoader referenced unknown path: /data/app/com.example.rcadit.foodgenie-1/lib/x86
D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                  [ 07-29 07:49:57.700  3218: 3218 D/         ]
                  HostConnection::get() New Host Connection established 0xae8acd80, tid 3218
D/android.widget.GridLayout: horizontal constraints: x2-x0&gt;=792, x2-x1&lt;=308, x1-x0&lt;=325 are inconsistent; permanently removing: x2-x1&lt;=308. 

                             [ 07-29 07:49:57.763  3218: 3236 D/         ]
                             HostConnection::get() New Host Connection established 0xae8acff0, tid 3236
I/OpenGLRenderer: Initialized EGL, version 1.4
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaab2cbf0
D/OpenGLRenderer: endAllStagingAnimators on 0xa9f31400 (ListPopupWindow$DropDownListView) with handle 0xad1d5ae0
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaab2f350
D/OpenGLRenderer: endAllStagingAnimators on 0xa9ef0c00 (ListPopupWindow$DropDownListView) with handle 0xa207d4a0
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaab2cbf0
D/OpenGLRenderer: endAllStagingAnimators on 0xa9ef5900 (ListPopupWindow$DropDownListView) with handle 0xa207d1a0
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaab2f350
I/SQLiteAssetHelper: successfully opened database foodfile.sqlite
E/SQLiteLog: (1) near "null": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.rcadit.foodgenie, PID: 3218
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rcadit.foodgenie/com.example.rcadit.foodgenie.resultActivity}: android.database.sqlite.SQLiteException: near "null": syntax error (code 1): , while compiling: SELECT foodName FROM foodDB where cuisine = null &amp; hungerLevel = null &amp; preparationTime null &amp; course = null
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                   Caused by: android.database.sqlite.SQLiteException: near "null": syntax error (code 1): , while compiling: SELECT foodName FROM foodDB where cuisine = null &amp; hungerLevel = null &amp; preparationTime null &amp; course = null
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
                      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
                      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                      at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
                      at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37)
                      at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
                      at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
                      at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)
                      at com.example.rcadit.foodgenie.DatabaseAccess.getResults(DatabaseAccess.java:72)
                      at com.example.rcadit.foodgenie.resultActivity.onCreate(resultActivity.java:21)
                      at android.app.Activity.performCreate(Activity.java:6237)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
I/Process: Sending signal. PID: 3218 SIG: 9
Application terminated.
</code></pre>

<p>I've spent the last 3 days trying to fix it and the other posts on this forum haven't worked for me. Any help would be greatly appreciated.</p>