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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:08:14+00:00 2026-06-01T20:08:14+00:00

I am building an android game that uses saves. That means that a user

  • 0

I am building an android game that uses saves. That means that a user can open up to 5 unique saves on the game. to create a new save, im using SharedPreferences to let the user enter a save name and store it in my SharedPreferences folder, and then redirect the user to the main game Activity with an Intent Extra that tells the game activity what save to open.

In the design it all sounds ok, but for some reason my application just keeps Force closing.
I dont have any code errors inside eclipse, and even LogCat shows no error. I dont know what
is going on…

Here is my code:

package ent.com;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class Saves extends ListActivity{

String saves[] = { "Empty save", "Empty save", "Empty save", "Empty save", "Empty save"};
public static String filename = "SharedData";
SharedPreferences someData;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    someData = getSharedPreferences(filename, 0);
    String save1 = someData.getString("0", "Empty save");
    String save2 = someData.getString("1", "Empty save");
    String save3 = someData.getString("2", "Empty save");
    String save4 = someData.getString("3", "Empty save");
    String save5 = someData.getString("4", "Empty save");

    saves[0] = save1;
    saves[1] = save2;
    saves[2] = save3;
    saves[3] = save4;
    saves[4] = save5;

    setListAdapter(new ArrayAdapter<String>(Saves.this, android.R.layout.simple_list_item_1, saves));

}

@Override
protected void onListItemClick(ListView l, View v,int position, long id) {
    final String clicked = saves[position];
    final String pos = getString(position);
    super.onListItemClick(l, v, position, id);
    if(clicked=="Empty save"){

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Input name");
        alert.setMessage("Give your team a name:");
        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        alert.setView(input);

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
          String value = input.getText().toString();
          SharedPreferences.Editor editor = someData.edit();
          editor.putString(pos, value);
          editor.commit();

          try{
          Class Joe = Class.forName("ent.com.TestActivity");
          Intent Joey = new Intent(Saves.this, Joe);
          Joey.putExtra("save", clicked);
          startActivity(Joey);
          }catch(ClassNotFoundException e){
              e.printStackTrace();
          }

          }
        });

        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            Intent back = new Intent("ent.com.MENU");
            startActivity(back);
          }
        });

        alert.show();
    }else{
    try{
    Class ourClass = Class.forName("ent.com.TestActivity");
    Intent ourIntent = new Intent(Saves.this, ourClass);
    ourIntent.putExtra("save", clicked);
    startActivity(ourIntent);
    }catch(ClassNotFoundException e){
        e.printStackTrace();
    }
    }
}

}

Thanks for any help.

  • 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-01T20:08:14+00:00Added an answer on June 1, 2026 at 8:08 pm

    So far all I see that is a big problem is this :

    if (clicked=="Empty save")
    

    == is for numbers and reference comparison. you’re looking for:

    if (clicked.equals("Empty save")) 
    

    which will actually compare the strings in question

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

Sidebar

Related Questions

I'm building a little Android game using libgdx. For now I have a copy
I am building an Android app for webradio. I am using vitamio player that
I'm building an Android puzzle game where the user rotates and shifts pieces of
I am building an Android app that parses an RSS feed using SAX parser.
I started building an Android app that uses a flat file for storage. The
I'm building an Android application that's based around an enhanced WebView (based on PhoneGap).
I am building an android game where objects randomly come in from either side
I'm building an open source 2D game engine called YoghurtGum. Right now I'm working
im building an android app and i need to save some files locally on
I'm building and Android app that needs to go through steps like a wizard.

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.