简体   繁体   English

为什么单击按钮后我的应用程序崩溃?

[英]Why does my App crash, when a Button is clicked?

I'm currently trying to program my first Android App. 我目前正在尝试编写我的第一个Android应用程序。 It's supposed to be a Sudoku solver, but I'm not that far yet. 它应该是Sudoku的求解器,但是我还没有那么远。 I kind of got stuck, because the App crashes when I try to click a Button. 我有点被卡住了,因为当我尝试单击按钮时,应用程序崩溃了。 The only Button that has an onClick function by now is grid_11 , so I cut out the rest which isn't important. grid_11 ,唯一具有onClick功能的Button是grid_11 ,因此我删除了其余的并不重要的按钮。 I hope someone can tell me, what I'm doing wrong. 我希望有人可以告诉我,我在做什么错。

package com.example.sudokusolver;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.SeekBar;



public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Button grid_11;

SeekBar seekBar;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    grid_11 = (Button)findViewById(R.id.grid_11);
    seekBar = (SeekBar)findViewById(R.id.seekBar);
    grid_11.setOnClickListener(this);


}


boolean solved = false;

@Override
public void onClick(View v){

   if (solved == false){
        switch(v.getId()){
            case R.id.grid_11:
                grid_11.setText(seekBar.getProgress());

       }
    }
  }
}

Replace below code 替换下面的代码

grid_11.setText(String.valueOf(seekBar.getProgress())); grid_11.setText(将String.valueOf(seekBar.getProgress()));

You can not set integer value into Button or Textview directly , you must to convert into String format. 您不能直接将整数值设置为Button或Textview,而必须将其转换为String格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM