EditText getText()致命失败

时间:2013-09-11 20:44:01

标签: android string android-edittext onclicklistener

我想保存用户输入的玩家的名字(在EditText中)。使用该按钮,用户可以切换到下一个,清除EditText并将其保存到变量。如果我在模拟器中运行它我得到一个错误,应用程序自行关闭。 你能告诉我失败是什么吗?我是Android编程的新手。 这是源代码:

public class inputName extends Activity {
TextView tv;
Button clear;
int players; //number of players from the Main Activity
private EditText name;
private String[] spielername;
private static final String TAG = MainActivity.class.getSimpleName();
  @Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.name);
    tv = (TextView) findViewById(R.id.textView1); //need that later
    name = (EditText) findViewById(R.id.editText1); 
    clear = (Button) findViewById(R.id.button1);
    getSpieler();
    saveName();

  }
  /*This method get the numbers of players from the first method. There is no error in it*/
 public void getSpieler() {
     SharedPreferences sharedPref = getSharedPreferences("FileName",MODE_PRIVATE);
     int spinnerValue = sharedPref.getInt("userChoiceSpinner",-1);
     players = spinnerValue;
     Log.e(TAG,"Es gibt "  +players);
 }
     public String[] saveName() { 
         for(int i=1;i<players;i++) {
             spielername[i] = name.getText().toString(); 
             clear.setOnClickListener(new View.OnClickListener(){

                    public void onClick(View v){
                        name.setText("");
                    }
                });
         }
        return spielername;

     }


  }

如果有人能帮助我,我会很高兴。来自德国的许多问候;)

0 个答案:

没有答案