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 6318709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:40:20+00:00 2026-05-24T15:40:20+00:00

I am developing an android which consists of a List View populated by a

  • 0

I am developing an android which consists of a List View populated by a blank database table with first option as “Create New”. When the user clicks on “Create New” a form is loaded which the user fills up and on clicking Save in the form this is stored in the database table of list view. Again when the user opens this list view it will have Create New as well as the form filled by user as options say
Create New and Form 1. There are few spinners in the form which are populated by an another table in the database

Everything is fine till here. When the user clicks on Form1 it loads the form he has filled for editing.

The problem I am facing is whenever the user loads the form and rotates the phone it is being FORCE CLOSED. Same thing is happening with list view also. Whenever I am in listview and rotate the Phone it is getting FORCE CLOSED.

here is my logcat

08-15 09:39:36.759: ERROR/AndroidRuntime(6481): FATAL EXCEPTION: main
08-15 09:39:36.759: ERROR/AndroidRuntime(6481): java.lang.NullPointerException  
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):at com.sufoin.mormeds.Submit$2.onItemSelected(Submit.java:366)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:871)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.AdapterView.selectionChanged(AdapterView.java:854)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:977)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.AdapterView.handleDataChanged(AdapterView.java:959)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:179)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481): at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:221)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:701)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.TableRow.onMeasure(TableRow.java:112)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:456)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at   android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.TableLayout.measureVertical(TableLayout.java:468)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.TableLayout.onMeasure(TableLayout.java:431)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:701)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1082)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.ScrollView.onMeasure(ScrollView.java:296)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.View.measure(View.java:8330)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1860)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.os.Looper.loop(Looper.java:123)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at java.lang.reflect.Method.invokeNative(Native Method)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at java.lang.reflect.Method.invoke(Method.java:507)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-15 09:39:36.759: ERROR/AndroidRuntime(6481):     at dalvik.system.NativeStart.main(Native Method)

Here is my code where the error has occured. it is used to initialize and set spinners

private void initandsetspinners(final Spinner gen, final Spinner prinum, final Spinner alternum, final Spinner precon, final Spinner dep, final Spinner pra, final Spinner add) {
    //Initializing the shared preferences variable
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

     //Creating an object called mydbhelper
    Dbms mydbhelper = new Dbms(this);
    //Loading the database in writable format
    final SQLiteDatabase db=mydbhelper.getWritableDatabase();

    //For Medicines Table
    try{
        //For medicines
        Cursor medspin = db.query("medicines", null,null,null,null,null,null);
        medspin.moveToPosition(prefs.getInt("pos",1));
        //Filling the variables to set selemedspintion
        deptpos=medspin.getInt(medspin.getColumnIndex("provider_department"));
        practipos=medspin.getInt(medspin.getColumnIndex("provider_practice"));
        addrpos=medspin.getInt(medspin.getColumnIndex("provider_address"));
        hsname=medspin.getString(medspin.getColumnIndex("healthsystem"));
        medspin.close();

        //For user_masterdata table
        Cursor userspin = db.query("user_masterdata", null,null,null,null,null,null);
        userspin.moveToPosition(0);
        //Filling the variables to set seleuserspintion
        genpos=userspin.getInt(userspin.getColumnIndex("gender"));
        pripos=userspin.getInt(userspin.getColumnIndex("primarynumbertype"));
        altpos=userspin.getInt(userspin.getColumnIndex("alternatenumbertype"));
        prefpos=userspin.getInt(userspin.getColumnIndex("prefcontactype"));
        userspin.close();

    }
    catch(Exception e){
        Log.e("Error","Error",e);
    }



    //Initializing the spinners
    //Gender
    ArrayAdapter<CharSequence> gentype = ArrayAdapter.createFromResource(this,R.array.gender, android.R.layout.simple_spinner_item);        
    gentype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    gen.setAdapter(gentype);

    //Primary Number
    ArrayAdapter<CharSequence> prinumtype = ArrayAdapter.createFromResource(this,R.array.pnumtype, android.R.layout.simple_spinner_item);        
    prinumtype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    prinum.setAdapter(prinumtype);

    //Alternate Number
    ArrayAdapter<CharSequence> altnumtype = ArrayAdapter.createFromResource(this,R.array.anumtype, android.R.layout.simple_spinner_item);        
    altnumtype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    alternum.setAdapter(altnumtype);

    //Preferred Contact type
    ArrayAdapter<CharSequence> preftype = ArrayAdapter.createFromResource(this,R.array.precontype, android.R.layout.simple_spinner_item);        
    preftype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    precon.setAdapter(preftype);

    try{

        //Cursor
        Cursor depcur = db.rawQuery("SELECT _id,department,"+prefs.getString("hsname",null)+ " FROM dept_masterdata WHERE "+prefs.getString("hsname",null)+"=1",null);
        depcur.moveToFirst();
        startManagingCursor(depcur);
        String[] from = new String[]{"department"};
        int[] to = new int[] { android.R.id.text1 };
         // Now creating an array adapter and set it to display using my row
        //Adaptor for Department
        SimpleCursorAdapter deptype =new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, depcur, from, to);
        deptype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dep.setAdapter(deptype);


    }
    catch(Exception e){
        Log.e("Error","Error",e);
    }
     //Now determine which department is selected
    //Department
    dep.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            deptid=dep.getSelectedItemId();

            //Setting the practice spinner based on the department selected
            Cursor pracur = db.rawQuery("SELECT _id,practice,dept_link,hs_id FROM practice_masterdata WHERE dept_link="+deptid+" AND hs_id="+(prefs.getInt("hsid",0)),null);
            pracur.moveToFirst();
            startManagingCursor(pracur);
            String[] from1 = new String[]{"practice"};
            int[] to1 = new int[]{android.R.id.text1};
            SimpleCursorAdapter practype =new SimpleCursorAdapter(view.getContext(),android.R.layout.simple_spinner_item, pracur, from1, to1);
            practype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            pra.setAdapter(practype);
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Practice
    pra.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){

            practid=pra.getSelectedItemId();

            //Setting the address  based on the practice selected
            Cursor addcur =db.rawQuery("SELECT * FROM address_masterdata WHERE practice_link="+practid,null);
            addcur.moveToFirst();
            startManagingCursor(addcur);
            String[] from2 = new String[]{"address"};
            int[] to2   = new int[]{android.R.id.text1};
            SimpleCursorAdapter addtype =new SimpleCursorAdapter(view.getContext(),android.R.layout.simple_spinner_item,addcur, from2, to2);
            addtype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            add.setAdapter(addtype);
            practicename=pra.getSelectedItem().toString();


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Address
    add.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            addrid=add.getSelectedItemId();  
            addressname=add.getSelectedItem().toString();
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });



    //Getting the info
    //Gender
    gen.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            gender=parent.getSelectedItem().toString();  


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Primary Number
    prinum.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            primarynumbertype=parent.getSelectedItem().toString();  


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Alternate Number 
    alternum.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            alternatenumbertype=parent.getSelectedItem().toString();  


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    //Preferred Contact type 
    precon.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent,View view,int pos,long id){
            prefferedcontactype=parent.getSelectedItem().toString();  


        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });




    //Setting the spinners based on the above variables
    gen.setSelection(genpos);
    prinum.setSelection(pripos);
    alternum.setSelection(altpos);
    precon.setSelection(prefpos);
    dep.setSelection(deptpos);
    pra.setSelection(practipos);
    add.setSelection(addrpos);



}

Line 366 is SimpleCursorAdapter practype =new SimpleCursorAdapter(view.getContext(),android.R.layout.simple_spinner_item, pracur, from1, to1);

Please Kindly help me out

Regards
Chinni krishna

  • 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-05-24T15:40:21+00:00Added an answer on May 24, 2026 at 3:40 pm

    As others have mentioned, when you change landscape, your Activity is being created again. Without seeing the code causing this, I wouldn’t be able to help fix it. But if all else fails, you can set the following on your Activity in the Android Manifest to not re-create the Activity on orientation change:

        <activity android:name="MainActivity" android:configChanges="orientation|keyboardHidden"></activity>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application in android in which i creating a list view
I'm developing on Android and currently haev various methods which manage my database in
I am developing one android application which select wifi access point from list of
I am developing an Android App which gives users an option 'Browse Alphanumerically'. Using
I am developing an Android app which uses the current user location for result.
When developing a new web based application which version of html should you aim
I'm currently developing my first android app, and my first game. I've been developing
I am developing an Android app which needs to poll a specific webpage in
We've been developing an Android application which includes Google Adsense. However there seems to
I am developing an application for the Android platform which contains 1000+ image filters

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.