Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8342625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:49:35+00:00 2026-06-09T05:49:35+00:00

My frist post only had less than half my text hence the second (complete)

  • 0

My frist post only had less than half my text hence the second (complete) post.

I’m working on a test app using sqlite to populate two AutoCompleteTextView’s i’m using car make and model for the test

AutoComplete’s:

makeAutocomplete

modelAutocomplete

makeAutocomplete’s list is populated from a sql query and it works fine

the second is populated when the make is selected

makeAutoComplete.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            final String[] makeSelected = {arg0.getItemAtPosition(arg2).toString()};
            final String[] modelDeal = sqlDBModel.getAllModelFilter(makeSelected);
            ArrayAdapter<String> modelAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line, modelDeal);
            initModelAutoComplete(modelAdapter);

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

initModelAutoComplete Declaration

public void initModelAutoComplete(ArrayAdapter<String> adapter){


    //adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, list);
    modelAutoComplete.setAdapter(adapter);
    modelAutoComplete.setThreshold(1);
    modelAutoComplete.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){
            arg0.getItemAtPosition(arg2);
        }
    });
}

SQLiteModelSearch.getAllModelFilter Declaration

    public String[] getAllModelFilter(String[] vehiclemake){

    if(vehiclemake != null){

        Cursor cursor = this.sqliteDBInstance.query(DB_MAKEMODEL_TABLE,
                                                    new String[]{DB_COLUMN_MAKE, DB_COLUMN_MODEL},
                                                    DB_COLUMN_MAKE+"=?",
                                                    vehiclemake,
                                                    null,
                                                    null,
                                                    null,
                                                    null);


        if( cursor != null){
            String[] str = new String[cursor.getCount()];

            int i = 0;
            while(cursor.moveToNext()){
                str[i] = cursor.getString(cursor.getColumnIndex(DB_COLUMN_MODEL));
                i++;
            }
            return str;
        } else {
            Log.i("vehiclemake = ", "NULL");
            return new String[]{};
        }
    }

    return new String[]{};
}

LogCat

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.app.ActivityThread.main(ActivityThread.java:3683)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
java.lang.reflect.Method.invokeNative(Native Method) 07-31
13:00:19.631: E/AndroidRuntime(1302): FATAL EXCEPTION: main

07-31 13:00:19.631: E/AndroidRuntime(1302):
java.lang.NullPointerException

07-31 13:00:19.631: E/AndroidRuntime(1302): at
com.myapp.sqltest.database.SQLiteModelSearch.getAllModelFilter(SQLiteModelSearch.java:100)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
com.myapp.sqltest.activity.addVehicleActivity$2.onItemSelected(addVehicleActivity.java:62)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.widget.AdapterView.fireOnSelected(AdapterView.java:871)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.widget.AdapterView.access$200(AdapterView.java:42)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:837)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.os.Handler.handleCallback(Handler.java:587)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.os.Handler.dispatchMessage(Handler.java:92)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
android.os.Looper.loop(Looper.java:130)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
java.lang.reflect.Method.invoke(Method.java:507)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

07-31 13:00:19.631: E/AndroidRuntime(1302): at
dalvik.system.NativeStart.main(Native Method)

I can see that the exception is being thrown at:

Cursor cursor = this.sqliteDBInstance.query(DB_MAKEMODEL_TABLE,
                                                    new String[]{DB_COLUMN_MAKE, DB_COLUMN_MODEL},
                                                    DB_COLUMN_MAKE+"=?",
                                                    vehiclemake,
                                                    null,
                                                    null,
                                                    null,
                                                    null);

but can’t tell why, i’ve watched all the variables going into the functions and none of them are null?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:49:37+00:00Added an answer on June 9, 2026 at 5:49 am

    I’ve figured it out. the issue was that I had defined

    public AutoCompleteTextView modelAutoComplete;
    public AutoCompleteTextView makeAutoComplete;
    

    Then then in function onCreate

    I had defined:

    AutoCompleteTextView modelAutoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteModel);
    AutoCompleteTextView makeAutoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteModel);
    

    I overlooked variable scope since both makeAutoComplete and modelAutoComplete where defined twice, one as a global class variable, and the second as a local function variable.

    since the global variable was only defined and not initialized. The function initModelAutoComplete() was referencing the global public variable modelAutoComplete causing the NPE exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My frist post only had less than half my text hence the second (complete)
I had a textarea, when i post that content in textarea, I only get
First post here... I normally develop using PHP and Symfony with Propel and ActionScript
I'm trying to write a voip app for Android, using the Android SIP API
UPDATE!! I am sorry for this post, the code I had written for this
I had an rcp application which runs for only first run, when a user
Hey, all. Working on my first Rails app. I've searched all around - read
I am working on a project using Drupal 6 (6.11 at the moment, haven't
I've asked this question on official Photon Server forums, but it's less active than
I'm working on a rather extensive mobile site using JQM (1.1.0). The structure is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.