gpt4 book ai didi

java - 启动画面后加载 SecondActivity 时出错

转载 作者:搜寻专家 更新时间:2023-11-01 07:52:53 25 4
gpt4 key购买 nike

我遇到了关于我的 SecondActivity Intent 的问题,主要 Activity 是带有进度条的初始屏幕。进度条间隔加载正常,当涉及到切换到下一部分并继续进行第二个 Activity 时,我收到一些无法追踪的错误并且非常忙。这是我的第二个 Activity 的代码:

package com.example.waleedmalik.computerparts;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ToggleButton;

public class SecondActivity extends AppCompatActivity {


ToggleButton tb;
Button btn;
public static boolean tbflag;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
tb = (ToggleButton)findViewById(R.id.toggleButton1);
btn = (Button)findViewById(android.R.id.button1);

btn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
tbflag = tb.isChecked();
Intent in = new Intent(getApplicationContext(),
GameActivity.class);

startActivity(in);

}

});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_second, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

最佳答案

像这样更改按钮初始化:

作为

btn = (Button)findViewById(android.R.id.button1);

线到

btn = (Button)findViewById(R.id.button1);

关于java - 启动画面后加载 SecondActivity 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32309511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com