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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:47:05+00:00 2026-05-23T08:47:05+00:00

In my app I get a Force Close, and I don’t know how to

  • 0

In my app I get a Force Close, and I don’t know how to solve this. The problem is that I have a class that extends ListActivity. In this class there is a list of shops, and the user should select one of the shops. If he not select a shop and press button Back I get Force Close, because the previous class expect the name of the shop. How can I catch this error?

Here is my class for selecting a shop :

public class SelectShop extends ListActivity {

private ListView lv1;
SimpleCursorAdapter adapter = null;
Cursor cursor;
DbAdapter db;
ImageView iconshop;

private static final int ADD=Menu.FIRST;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.shopselect);

    iconshop = (ImageView) findViewById(R.id.iconshop);
    lv1 = getListView();

    DbApplication myApplication = (DbApplication) this.getApplication();
    db= myApplication.getDatabaseAdapter();

    cursor = db.getAllShops();
    startManagingCursor(cursor);
    if (cursor != null && cursor.moveToFirst()){
    adapter = new SimpleCursorAdapter(this, R.layout.shopsrow, cursor,
            new String[] { DbAdapter.NAME, DbAdapter.ADRESS }, new int[] {
                    R.id.title, R.id.address });

    setListAdapter(adapter);
    }else Toast.makeText(this,
            "Choose Menu for adding a shop",
            Toast.LENGTH_LONG).show();

    lv1.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {
            Intent j = new Intent(SelectShop.this,
                    com.ShoppingList.NewList.class);

            Cursor c = (Cursor) parent.getAdapter().getItem(position);
            j.putExtra("shop", c.getString(c.getColumnIndex(db.NAME)));
            setResult(RESULT_OK, j);
            finish();
        }
    });
}
/*Adaugarea meniului Add Shop*/
public boolean onCreateOptionsMenu(Menu menu) { 
    menu.add(0, ADD, 0, "Add Shop").setIcon(R.drawable.additem); 
    return true; 
    }

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case ADD:
        Intent j = new Intent(SelectShop.this, Shops.class);
        startActivityForResult(j, 0);
        return true;
    }
    return false;
}

}

and in previuos class I have this:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        switch (requestCode) {
        case 0: {
            Bundle b = intent.getExtras();
            shopselect = b.getString("shop");
            shop.setText(shopselect);
        }
            break;
}
}
  • 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-23T08:47:05+00:00Added an answer on May 23, 2026 at 8:47 am

    I think you need to implement a mechanism that won’t let your user get back to previous activity without choosing any item in the list. Override your onKeyDown() method, and when the user presses Back key you should check whether any item is chosen. If it’s not you can throw an alert dialog to inform user what he must do to proceed. Hope this helps!

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

Sidebar

Related Questions

after the phone reboot or the app force close the listener that i set
I have been trying for 4 days to get app-engine and grails working together
In the app I am working on, I have an AlarmManager that starts a
So, I have written an app that has a Main activity (A), and various
I hope I can explain this properly. I'm making an android app that, when
This is my very first attempt at including ads in my app. I have
In my app, I have a service that gets the location of the device
I Get force close when executed on Android emulator. I can't figure out the
I have a little/big problem in my app in android.I have 2 activity:Activity1 and
I have an android app that connects to the internet to do a reverse

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.