我是 android studio 的新手,我不明白為什么當(dāng)我開始使用搜索欄時我的應(yīng)用程序崩潰了。有人可以幫我嗎?公共類 MainActivity 擴展 AppCompatActivity { SeekBar seeBar; //聲明seekbar對象TextView textView, textView2; 列表視圖簡單列表視圖;//為SeekBar聲明成員變量 int離散; int開始= 50;int 起始位置 = 50; //進度跟蹤器 int temp = 0; //為ViewStub聲明對象ViewStub存根; 復(fù)選框復(fù)選框;列表視圖lv; //聲明Listview對象Button按鈕; 查看視圖;public MainActivity() { discrete = 0;}@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //declare viewstub object stub = findViewById(R.id.viewStub1); @SuppressWarnings("unused") View inflated = stub.inflate(); stub.setVisibility(View.INVISIBLE); //ViewStub logic checkBox = findViewById(R.id.checkBox1); //handle checkbox click event checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { if (isChecked) { //remove objs from parent view to allow for child view objs checkBox.setVisibility(View.GONE); seekBar.setVisibility(View.GONE); textView.setVisibility(View.GONE); stub.setVisibility(View.VISIBLE); } } }); //seekbar logic textView = findViewById(R.id.textview); textView = findViewById(R.id.textView2); textView.setText(" Celsius at 0 degrees"); //set default view seekBar = findViewById(R.id.seekbar); seekBar.setProgress(start_position); //create event handler for SeekBar seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){ @Override public void onStopTrackingTouch(SeekBar seekBar) { if (temp == 0) { //for initial view result //Toast.makeText(getBaseContext(), "Fahrenheit result: 32 degrees", //Toast.LENGTH_SHORT).show(); textView2.setText("Fahrenheit result 32 degrees") ; }
3 回答

侃侃爾雅
TA貢獻1801條經(jīng)驗 獲得超16個贊
TextView textView = findViewById(R.id.textview); TextView textView2 = findViewById(R.id.textView2);

拉風(fēng)的咖菲貓
TA貢獻1995條經(jīng)驗 獲得超2個贊
textView = findViewById(R.id.textview); textView = findViewById(R.id.textView2);
textView2 此處未初始化...
將上面的代碼改為
textView = findViewById(R.id.textview); textView2 = findViewById(R.id.textView2);
添加回答
舉報
0/150
提交
取消