我有以下int

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentView(R.layout.activity_score);
    // Show the Up button in the action bar.
    setupActionBar();
    Intent i = getIntent();
    String max = i.getStringExtra(MainActivity.EXTRA_MAX);
    final int maxInt = Integer.parseInt(max);


我想从这里访问它:

public void plus1 (View V)
{
    maxInt ++;
}


但是即使在不使用final的情况下,当int在类内部时,也会出现错误:

public class ScoreActivity extends Activity {


我崩溃了

最佳答案

int maxInt;之前但在类内部声明onCreate()

并更改您的代码

final int maxInt = Integer.parseInt(max);



maxInt = Integer.parseInt(max);

关于android - Android-无法通过onCreate()方法访问int,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17641188/

10-10 23:20
查看更多