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

  • Home
  • SEARCH
  • 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 6208343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:47:31+00:00 2026-05-24T05:47:31+00:00

Is anyone able to see why my string with a made up name is

  • 0

Is anyone able to see why my string with a made up name is not attaching itself to a value?

public void setNames() {

    //*******************//
    //***DATABASE INFO***//
    //*******************//
    DBAdapter db = new DBAdapter(this);

    if (totalPlayerCount >= 1){  


    //**********************//
    //***SET PLAYER NAMES***//
    //**********************//
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Player " + nameLoop);
    alert.setMessage("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 newName = "name"+nameLoop;
      // If i put "name1" here like so, the value "wow" stays with "name1" all the way to the database and does not end up null
      name1 = "wow";
      newName = input.getText().toString(); <-- newName should be name1, name2, name3, name4 each time around.  If i do a simple Toast, it displays name1, name2, etc.  But when i insert those values into the database, they are all null.
      setNames();
      }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
      }
    });

    alert.show();

    nameLoop++;

    }
    if (totalPlayerCount == 0){
        db.open();
        db.insertPlayers(String.valueOf(name1), String.valueOf(name2), String.valueOf(name3),
                String.valueOf(name4));
        db.close();

        AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
        //myAlertDialog.setTitle("Saved");
        myAlertDialog.setMessage("Names saved");
        myAlertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
                return;
            } }); 
        myAlertDialog.show();
    }   
    totalPlayerCount--;
    return;
}

Here is the same clip just broken out that I am having trouble with

public void onClick(DialogInterface dialog, int whichButton) {
      String newName = "name"+nameLoop;
      // If i put "name1" here like so, the value "wow" stays with "name1" all the way to the database and does not end up null
      name1 = "wow";
      newName = input.getText().toString(); <-- newName should be name1, name2, name3, name4 each time around.  If i do a simple Toast, it displays name1, name2, etc.  But when i insert those values into the database, they are all null.
      setNames();
      }
    });
  • 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-24T05:47:32+00:00Added an answer on May 24, 2026 at 5:47 am

    You cannot dynamically create a variable and then assign it a value. Java does not work like javascript.

    You have to replace your

      String newName = "name"+nameLoop;
      // If i put "name1" here like so, the value "wow" stays with "name1" all the way to the database and does not end up null
      name1 = "wow";
      newName = input.getText().toString(); <-- newName should be name1, name2, name3, name4 each time around.  If i do a simple Toast, it displays name1, name2, etc.  But when i insert those values into the database, they are all null.
    

    section with a switch statement.

    String newName = input.getText().toString();
    switch(nameLoop){
    case 1: name1=newName;break;
    case 2: name2=newName;break;
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would anyone be able to tell me how to pull the server name out
anyone able to tell me how often a materialized view is set to refresh
Has anyone been able to get an NHibernate-based project up and running on a
Has anyone been able to get xinc to run correctly under OpenBSD's chrooted default
Has anyone been able to get a variable record length text file (CSV) into
Has anyone been able to successfully unit test methods that are, by necessity, coupled
Has anyone been able to create Container-Specific Master Pages for Safari or Chrome? I
Has anyone been able to succesfully use the IE CSS hack #IEroot? I stumbled
Has anyone been able to implement the JQuery grid plugin, jqGrid? I'm trying to
Has anyone been able to customize jQGrid? While I'd like something easy I can

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.