I have MainActivity.class that has some methods. Here is the method I want to call when the app starts:
public void loadGame(View view) {
SharedPreferences loadGame = getSharedPreferences(PREFS, MODE_PRIVATE);
cashView.setText("cash: " + String.valueOf(cash));
levelView.setText("level: " + String.valueOf(level));
}
So I try to type in the following in my onCreate method:
loadGame();
But I get an error: (View) in MainActivity cannot be applied to ()
Sorry for such a silly question but I don't get it. I thought that onCreate and other activity methods are similar to main method in Java (but they are not), but still I can easily assign a method for Button onClick. Why can't I call a method when the app starts? Any solution?
upd: MainActivity code:
public class MainActivity extends AppCompatActivity {
private int cash = 1000;
private int level = 1;
private TextView cashView;
private TextView levelView;
public static final String PREFS = "MySavedGameFile";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//the compiler says it cannot resolve symbol 'view'
// loadGame(view);
//I need to call the method anyway
cashView = (TextView) findViewById(R.id.cashView);
levelView = (TextView) findViewById(R.id.levelView);
}
public void loadGame(View view) {
SharedPreferences loadGame = getSharedPreferences(PREFS, MODE_PRIVATE);
cash = loadGame.getInt("savedCash", 1000);
level = loadGame.getInt("savedLevel", 1);
cashView.setText("Cash: " + String.valueOf(cash));
levelView.setText("Level: " + String.valueOf(level));