Даже если я не использовал статический, я получаю предупреждение ниже - PullRequest
0 голосов
/ 22 ноября 2018

Я получаю предупреждение "нестатическая переменная переменная не может быть вызвана из статического контекста", хотя я не использовал выражение static в Android Studio.Я не понимаю почему.Не могли бы вы помочь?

Я пытался поделиться кодом, но я слишком долго не мог.

Проблема запускается после метода onClick.

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    // gameStart = (Button) findViewById(R.id.start);
    newRoundButton = (Button) findViewById(R.id.newRound);
    hitButton = (Button) findViewById(R.id.hit);
    newGameButton = (Button) findViewById(R.id.newGame);
    passButton = (Button) findViewById(R.id.pass);

    playerC1 = (ImageView) findViewById(R.id.playerC1);


    newRoundButton.setOnClickListener(this);
    hitButton.setOnClickListener(this);
    newGameButton.setOnClickListener(this);
    passButton.setOnClickListener(this);

    //hitButton.setVisibility(View.INVISIBLE);
    //newGameButton.setVisibility(View.INVISIBLE);
    // passButton.setVisibility(View.INVISIBLE);

    dealer = (TextView) findViewById(R.id.dealer);
    player = (TextView) findViewById(R.id.player);
    playerTotal = (TextView) findViewById(R.id.playerTotal);
    dealerDeckTable = (TextView) findViewById(R.id.dealerDeckTable);
    playerDeckTable = (TextView) findViewById(R.id.playerDeckTable);
    skor = (TextView) findViewById(R.id.score);
    gameMessage = (TextView) findViewById(R.id.gameMessage);
    dealerTotal = (TextView) findViewById(R.id.dealerTotal);
    playerSkor = (TextView) findViewById(R.id.playerSkor);
    dealerSkor = (TextView) findViewById(R.id.dealerSkor);
    kontrol = (TextView) findViewById(R.id.kontrol);
    playerDeckTable = (TextView) findViewById(R.id.playerDeckTable);
    dealerDeckTable = (TextView) findViewById(R.id.dealerDeckTable);

    playerC1.setImageDrawable((ContextCompat.getDrawable(getApplicationContext(),R.drawable.nocard)));

}
 public void onClick(View v) {
   if (v.getId() == newGameButton.getId()) {
        gameMessage.setText(Cards.firstStart());
        playerSkor.setText(Cards.pskorS);
        dealerSkor.setText(Cards.dskorS);
        playerTotal.setText(Cards.pValS);
        dealerTotal.setText("N/A");
        playerDeckTable.setText(Cards.pHand);
        dealerDeckTable.setText(Cards.dHand2);
        newGameButton.setVisibility(View.INVISIBLE);
        kontrol.setText(Cards.kontrolS);

код продолжается ...

Cards класс не содержит статической переменной, и я получаю, что строки предупреждения получают информацию от Карты класс.

Надеюсь, подробностей достаточно, чтобы объяснить проблему ..

1 Ответ

0 голосов
/ 22 ноября 2018

Проблема в том, что вы вызываете Cards.firstStart () как статический метод.Вы должны инициализировать свой Cardobject с Cards cards = new Cards()

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...