mercredi 10 juin 2020

Error 'unknown class' in Android Studio while using variables in control statements

I am creating a music app which use two or more buttons(simultaneously) to make a specific sound. So i created methods for each buttons respectively (calls when respective button is clicked)which return '1'. And then i assigned its value to some integer variables (value of each method in each variable). But whenever i tried to use these variables in 'if' statement, i am getting an error which says: "unknown class". what should i do to solve this error? please explain what mistake i made to my code and help me to correct it.

CODE:

package unique.com;

import androidx.appcompat.app.AppCompatActivity;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    // TODO: Add member variables here
    private SoundPool mSoundPool;
    private int mCSoundId;
    private int mDSoundId;
    private int mESoundId;
    private int mFSoundId;
    private int mGSoundId;
    private int mASoundId;
    private int mBSoundId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // TODO: Create a new SoundPool
        mSoundPool = new SoundPool(7, AudioManager.STREAM_MUSIC,0);



        // TODO: Load and get the IDs to identify the sounds
        mCSoundId = mSoundPool.load(getApplicationContext(),R.raw.cc,1);
        mDSoundId = mSoundPool.load(getApplicationContext(),R.raw.dd,1);
        mESoundId = mSoundPool.load(getApplicationContext(),R.raw.ee,1);
        mFSoundId = mSoundPool.load(getApplicationContext(),R.raw.ff,1);
        mGSoundId = mSoundPool.load(getApplicationContext(),R.raw.gg,1);
        mASoundId = mSoundPool.load(getApplicationContext(),R.raw.aa,1);
        mBSoundId = mSoundPool.load(getApplicationContext(),R.raw.ff,1);
    }

    // TODO: Add the play methods to add 1 to each button

    public static int playC(){

        return 1;
    }

    public static int playD(){

        return 1;
    }

    public static int playE(){

        return 1;
    }

    public static int playF(){

        return 1;
    }

    public static int playG(){

        return 1;
    }

    public static int playA(){

        return 1;
    }

    public static int playB(){

        return 1;
    }

    // assigning values to variables

    final int cc = playC();
    final int dd = playD();
    final int ee = playE();
    final int ff = playF();
    final int gg = playG();
    final int aa = playA();
    final int bb = playB();

    // Checking the values in variables

if (cc == 1){      <--ERROR AT THIS LINE:"unknown class:cc"


}

Aucun commentaire:

Enregistrer un commentaire