0

I am trying to create one form.but at the time of adding spinner it is showing null pointer exception.What should i do?How Can i Solve this? Everytime i use spinner it gets me error at setAdapter() method this is my code...

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
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.Spinner;

import java.util.ArrayList;
import java.util.List;

public class Complaint extends AppCompatActivity implements       AdapterView.OnItemSelectedListener {

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    Spinner sp=(Spinner) findViewById(R.id.spinner);
    List<String> categories = new ArrayList<String>();
    categories.add("चौकशी");
    categories.add("तक्रार");
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>   (getApplicationContext(), android.R.layout.simple_spinner_item,categories );

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    sp.setAdapter(dataAdapter);

    sp.setOnItemSelectedListener(this);

}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}}
  • 2
    Post the code and logcat here. You can also read this: http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it – Rick S Oct 10 '16 at 14:28
  • I have posted my code.click on my code –  Oct 10 '16 at 14:36
  • i am having issue while adding the method spiner.setAdapter() –  Oct 10 '16 at 14:46

0 Answers0