logo
down
shadow

Android Spinner nullpointer


Android Spinner nullpointer

By : user2186907
Date : November 25 2020, 04:01 AM
hop of those help? Check you xml file because your statusstop1 is null. Make sure in your xml statusstop id available in spinner.
code :


Share : facebook icon twitter icon
Nullpointer Exception in FragmentActivity while showing data in Spinner from database

Nullpointer Exception in FragmentActivity while showing data in Spinner from database


By : Adrian
Date : March 29 2020, 07:55 AM
Does that help I am getting a problem in FrameActivity with FragmentPagerAdapter to declare my swipe-able tabs. In one of tabs contain Spinner in which i want to collect data from database. First i am going to post my FrameActivity
code :
Spinner is not define in above TranscationMain's layout, It define in below Fragment
Spinner spinner_question;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.new_entry, container, false);
spinner_question = (Spinner)rootView.findViewById(R.id.spinner_category);
return rootView;
}
Using Spinner from String Array:NullPointer Exception

Using Spinner from String Array:NullPointer Exception


By : abam1817
Date : March 29 2020, 07:55 AM
I wish this helpful for you I am new to Android and don't know much. Please help me with this problem , You should initiate spinner:
code :
spinner1 = (Spinner)rootView.findViewById(R.id.spinner1);
spinner1.setAdapter(dataAdapter);
(android) Nullpointer exception while setting a spinner

(android) Nullpointer exception while setting a spinner


By : Pontakorn Sonchan
Date : March 29 2020, 07:55 AM
I hope this helps you . Finally i solved the problem. as was posted here:
In my adaper I used:
code :
view = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, null);
view = inflater.inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
Android Spinner: Populate second and thrid spinner based on first spinner filter

Android Spinner: Populate second and thrid spinner based on first spinner filter


By : user3312068
Date : March 29 2020, 07:55 AM
will help you The following is an example based upon some of the code from the question, that has 3 spinners the 2nd listing values as determined according to what is selected by spinner1. Likewise the 3rd listing values as determined by what is selected by spinner2.
In short each spinner has a manageSprinner? method (? being 1, 2 and 3 respectively).
code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />
    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <Spinner
        android:id="@+id/spinner2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />
</LinearLayout>
public class DatabaseHandler extends SQLiteOpenHelper {
    // Database Version
    public static final int DATABASE_VERSION = 1;

    public static final String DATABASE_NAME = "spinnerExample";
    private final Context myContext;
    private SQLiteDatabase myDataBase;
    // Database Name
    // Labels table name
    public static final String TABLE_LABELS = "labels"; //<<<< Made public
    public static final String TABLE_LABELS1= "labels1";
    public static final String TABLE_LABELS2= "labels2";
    // Labels Table Columns names
    public static final String KEY_ID4 = "input_label";
    public static final String KEY_ID12 = "id2";           //<<<< Made public
    public static final String KEY_ID = "id";
    public static final String KEY_99 = "sno";           //<<<< Made public//<<<< Made public
    public static final String KEY_NAME = "name";       //<<<< made public
    public static final String KEY_ID1 = "id1";           //<<<< Made public
    public static final String KEY_NAME1 = "name1";
    public static final String KEY_1 = "number";           //<<<< Made public
    public static final String KEY_2 = "outletname";       //<<<< made public
    public static final String KEY_3 = "sunday";           //<<<< Made public
    public static final String KEY_4 = "monday";
    public static final String KEY_5 = "tuesday";
    public static final String KEY_6 = "wednesday";
    public static final String KEY_7 = "thursday";
    public static final String KEY_8 = "saturday";
    public static final String KEY_9 = "closed";
    public static final String KEY_10 = "calling";
    public static final String KEY_11 = "id3";
    public DatabaseHandler(Context context) {

        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        myDataBase = this.getWritableDatabase();
        this.myContext = context;
    }

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        //boolean dbExist = checkDataBase();
        // Category table create query
        String CREATE_CATEGORIES_TABLE = "CREATE TABLE " + TABLE_LABELS + "("+ KEY_99 + " INTEGER,"
                + KEY_ID1 + " TEXT," + KEY_ID + " TEXT," + KEY_NAME + " TEXT)";
        String CREATE_CATEGORIES_TABLE1 = "CREATE TABLE " + TABLE_LABELS1 + "("
                + KEY_ID1+ " TEXT," + KEY_NAME1+ " TEXT)";
        String CREATE_CATEGORIES_TABLE2 = "CREATE TABLE " + TABLE_LABELS2 + "("
                + KEY_11+ " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_1+ " TEXT," + KEY_2+ " TEXT," + KEY_3+ " INTEGER," + KEY_4+ " INTEGER,"+ KEY_5+ " INTEGER," + KEY_6+ " INTEGER," + KEY_7+ " INTEGER," + KEY_8+ " INTEGER," + KEY_9+ " INTEGER," + KEY_10+ " TEXT)";
        db.execSQL(CREATE_CATEGORIES_TABLE);
        db.execSQL(CREATE_CATEGORIES_TABLE1);
        db.execSQL(CREATE_CATEGORIES_TABLE2);
    }
    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS1);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS2);
        // Create tables again
        onCreate(db);
    }

    /**
     * Inserting new lable into lables table
     * */
    public void insertLabel(String message1, String message2,String message3,String message4,String message5,String message6,String message7,String message8,String message9,String message10){
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_1, message1);
        values.put(KEY_2, message2);
        values.put(KEY_10,message10);
        values.put(KEY_4,message4);
        values.put(KEY_5,message5);
        values.put(KEY_6,message6);
        values.put(KEY_7,message7);
        values.put(KEY_3,message3);
        values.put(KEY_9,message9);
        values.put(KEY_8,message8);
        // Inserting Row
        db.insert(TABLE_LABELS2, null, values);
        //db.close(); // Closing database connection
    }

    public void insertLabel1(String label){
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_NAME1, label);
        db.insert(TABLE_LABELS1, null, values);
        //db.close(); // Closing database connection
    }

    public void insertLabel2(String label){
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(KEY_NAME, label);
        db.insert(TABLE_LABELS, null, values);
        db.close(); // Closing database connection
    }


    public Cursor getAllLabelsForSpinner1AsCursor() {
        String[] columns = new String[]{"rowid AS _id, *"}; // Need _id column for SimpleCursorAdapter
        return this.getWritableDatabase().query(TABLE_LABELS2,columns,null,null,null,null,null);
    }


    public Cursor getAllLabelsForSpinner2AsCursor(String keyFromSinner1) {
        String[] columns = new String[]{"rowid AS _id, *"}; // Need _id column for SimpleCursorAdapter
        return this.getWritableDatabase().query(
                TABLE_LABELS1,columns,
                DatabaseHandler.KEY_NAME1 + " LIKE ?",
                new String[]{keyFromSinner1+"%"},
                null,null,null
        );
    }

    public Cursor getAllLabelsForSpinner3AsCursor(String keyFromSpinner2) {
        String[] columns = new String[]{"rowid AS _id, *"}; // Need _id column for SimpleCursorAdapter
        return this.getWritableDatabase().query(
                TABLE_LABELS,columns,
                DatabaseHandler.KEY_NAME + " LIKE ?",
                new String[]{keyFromSpinner2 + "%"},
                null,null,null);
    }
}
public class MainActivity extends AppCompatActivity {

    DatabaseHandler mDH;
    Spinner mSpinner1,mSpinner2,mSpinner3;
    Cursor mSpinner1Csr,mSpinner2Csr,mSpinner3Csr;
    SimpleCursorAdapter mSpinner1Adapter,mSpinner2Adapter,mSpinner3Adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mSpinner1 = this.findViewById(R.id.spinner1);
        mSpinner2 = this.findViewById(R.id.spinner2);
        mSpinner3 = this.findViewById(R.id.spinner3);
        mDH = new DatabaseHandler(this);
        addSomeTestingData(); // ADD testing data if none
        manageSpinner1(); // Manages spinner1 not that spinner 1 invokes manage spinner2 and spinnr manages spinner3

    }

    private void addSomeTestingData() {
        if(DatabaseUtils.queryNumEntries(mDH.getWritableDatabase(),DatabaseHandler.TABLE_LABELS) > 0) return;

        // Data for LABELS2 table (spinner 1 (note 1st column listed in spinner))
        mDH.insertLabel("A1","A2","A3","A4","A5","A6","A7","A8","A9","A10");
        mDH.insertLabel("B1","B2","B3","B4","B5","B6","B7","B8","B9","B10");
        mDH.insertLabel("L1","L2","L3","L4","L5","L6","L7","L8","L9","L10");

        // Data for LABELS1 table (spinner 2)
        mDH.insertLabel1("A1EXTRA1");
        mDH.insertLabel1("A1EXTRA2");
        mDH.insertLabel1("B1EXTRA1");
        mDH.insertLabel1("B1EXTRA2");
        mDH.insertLabel1("L1EXTRA1");
        mDH.insertLabel1("L1EXTRA2");

        // Data for LABELS table (spinner 3)
        mDH.insertLabel2("A1EXTRA1MORE1");
        mDH.insertLabel2("A1EXTRA1MORE2");
        mDH.insertLabel2("A1EXTRA2MORE1");
        mDH.insertLabel2("A1EXTRA2MORE2");
        mDH.insertLabel2("B1EXTRA1MORE1");
        mDH.insertLabel2("B1EXTRA1MORE2");
        mDH.insertLabel2("B1EXTRA2MORE1");
        mDH.insertLabel2("B1EXTRA2MORE2");
        mDH.insertLabel2("L1EXTRA1MORE1");
        mDH.insertLabel2("L1EXTRA1MORE2");
        mDH.insertLabel2("L1EXTRA2MORE1");
        mDH.insertLabel2("L1EXTRA2MORE2");

    }

    private void manageSpinner1() {
        mSpinner1Csr = mDH.getAllLabelsForSpinner1AsCursor();
        if (mSpinner1Adapter == null) {
            mSpinner1Adapter = new SimpleCursorAdapter(
                    this,
                    android.R.layout.simple_list_item_1,
                    mSpinner1Csr,
                    new String[]{DatabaseHandler.KEY_1},
                    new int[]{android.R.id.text1},
                    0
            );
            mSpinner1.setAdapter(mSpinner1Adapter);
            mSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    manageSpinner2(mSpinner1Csr.getString(mSpinner1Csr.getColumnIndex(DatabaseHandler.KEY_1)));
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });
        } else {
            mSpinner1Adapter.swapCursor(mSpinner1Csr);
        }
    }
    private void manageSpinner2(String keyFromSpinner1) {
        mSpinner2Csr = mDH.getAllLabelsForSpinner2AsCursor(keyFromSpinner1);
        if (mSpinner2Adapter == null) {
            mSpinner2Adapter = new SimpleCursorAdapter(
                    this,
                    android.R.layout.simple_list_item_1,
                    mSpinner2Csr,
                    new String[]{DatabaseHandler.KEY_NAME1},
                    new int[]{android.R.id.text1},
                    0
            );
            mSpinner2.setAdapter(mSpinner2Adapter);
            mSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    manageSpinner3(mSpinner2Csr.getString(mSpinner2Csr.getColumnIndex(DatabaseHandler.KEY_NAME1)));
                }

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

                }
            });
        } else {
            mSpinner2Adapter.swapCursor(mSpinner2Csr);
        }
    }

    private void manageSpinner3(String keyForSpinner3) {
        mSpinner3Csr = mDH.getAllLabelsForSpinner3AsCursor(keyForSpinner3);
        if (mSpinner3Adapter == null) {
            mSpinner3Adapter = new SimpleCursorAdapter(
                    this,
                    android.R.layout.simple_list_item_1,
                    mSpinner3Csr,
                    new String[]{DatabaseHandler.KEY_NAME},
                    new int[]{android.R.id.text1},
                    0
            );
            mSpinner3.setAdapter(mSpinner3Adapter);
        } else {
            mSpinner3Adapter.swapCursor(mSpinner3Csr);
        }
    }
}
NullPointer on loading strings into spinner

NullPointer on loading strings into spinner


By : ilyass
Date : March 29 2020, 07:55 AM
I hope this helps you . In the while statement, final2.add(read) is getting a nullpointer which leads me to believe that it is not reading the file correctly, so my question is the following am I obtaining the contents of the text file correctly? , You need to initialize your final2 variable.
Related Posts Related Posts :
  • How do I make this image larger?
  • Run icCube with JDK 10
  • Expression with Math.random() always returns the same value
  • Getting the Set with the most elements nested in a HashMap using Java Streams
  • XmlSlurper to parse XML and get value of inside elements using Groovy
  • Extracting data from HTML and formatting the output
  • SOLR documentCache JMX metrics clarification
  • Limiting Wildfly 14 Two-Way SSL to specific clients
  • How do I get Min and max values to only print when "year" is entered?
  • Hashmap can't loop - getKey() method not found - Using Java 8
  • Android Studio - Create an EditText with a click of a button
  • Mockito Test not invoking verify() method
  • Wrap method implementations of Java interfaces
  • Remediating dynamic SQL into prepared statements
  • Where do X and Y start at in swing windows
  • java code with files work from eclipse but dont work from cmd
  • Return page object from JPA query
  • I can't figure out why this code in my APCS multiple choice book returns 19
  • How to save data between methods
  • I'm trying to install Apache Gobblin. How can I install it using Gradle?
  • Spring Data Sorting Array or Set into Pageable
  • Question about the Java documentation and its implementation
  • How to make a JButton that when pressed it does a new action
  • Java hibernate No validator could be found for boolean
  • Making a POJO Thread Safe
  • Save the data of a text file in a arraylist
  • Sort a List<String[]> by indices using Comparator
  • Overloading in Java for user input?
  • Unable to format timestamp as YYYY-MM-DD HH:mm:ss in java
  • Access SQLite Helper From Adapter
  • How to stream a csv file with header to a HashMap<String, Double> in Java?
  • can't get go daddy ssl certificate to work with spring boot
  • ResourceBundle can't find BaseName gradle project java
  • Java; Jackson; Parsing the array of array json string
  • Java - map key lookup ignoring case
  • Jackson deserialize map null values to empty string
  • Anyone knows why setCount() is not working in twitter4j?
  • Object Visibility in a Multi-threaded Program in Java
  • Can't store and load an arraylist in an object file
  • convert a string number starts with `00` to `+` in java
  • Java - avoiding NonSuchElementException using ConcurrentLinkedDeque
  • Converting Immutable to mutable list Java
  • Getting nosuchmethod exception
  • How to get MQTT subscriptions
  • Android Google Sign in Exceptions
  • JavaFX - method that waits for user input
  • Replacing values for a particular key in treemap changes values for every key
  • This method call passes a null value for a nonnull method parameter. Either the parameter is annotated as a parameter th
  • Kafka: consume all messages on demand
  • Notify what text was changed in textview
  • Tinkerpop/Gremlin: select vertices together with outgoing edge count
  • transform a list of objects into a list of integers that pass a check
  • Why this java code is showing strange behavior?
  • Maven Project classes not compiling
  • Edit image to make text more clear opencv
  • Add result to int array every time you finish counting the occurrence
  • Android import java library
  • How to use LDAP Authentication in a corporate environment
  • adding item during iteration in java special usecase
  • How can I sort a map with string key? like (1 foo , 2 foo)
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org