0

嘿伙计们,我知道已经有很多相同的帖子,我已经关注了每个帖子。

在这里我面临一个问题,需要知道这个问题。

我明天要发布我的应用程序,所以需要帮助。

我曾尝试将它与 string 和 int 一起使用,但它们都没有工作并给出错误。

谢谢

我的代码:

package com.droidacid.apticalc.tys;

import com.droidacid.apticalc.R;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.widget.TextView;

public class HighScores extends Activity {

TextView tvHighScore;
private static String SCORE_KEY = "savedScore";
String myScore;
int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tys_high_score);
    tvHighScore = (TextView) findViewById(R.id.tv_tys_score);
    getScore();

}



private void getScore() {
    Bundle getScore = getIntent().getExtras();
    score = getScore.getInt("score");
    myScore = Integer.toString(score);
    setScore(score);
    getScore(score);

}

private void setScore(int score) {
    SharedPreferences saveScore = getSharedPreferences("saveScores",     MODE_PRIVATE);
    SharedPreferences.Editor editor = saveScore.edit();
    editor.putString(SCORE_KEY, myScore);
    editor.commit();

}
SharedPreferences saveScore = getSharedPreferences("saveScores", MODE_PRIVATE);
tvHighScore.setText(saveScore.getString(SCORE_KEY, ""));



@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}
}
4

1 回答 1

0

It's because that these two lines are not in any method.

SharedPreferences saveScore = getSharedPreferences("saveScores", MODE_PRIVATE);

tvHighScore.setText(saveScore.getString(SCORE_KEY, ""));

Try to put these two lines in your on create method and you will see that this error will stop. Tell me how it goes.

于 2013-06-20T08:01:24.293 回答