java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法'int android.os.Bundle.getInt(java.lang.String,int)'

时间:2019-05-26 17:46:49

标签: java android nullpointerexception

嘿,我在android studio和java上还很新。我有一个错误,当应用程序从调试启动或Google Play商店启动时,应用程序崩溃,但是当我通过单击符号启动应用程序时,应用程序启动并运行。我认为错误是因为开始新活动或加载共享首选项

请帮助

JAY1234     {eve = {nFields = {ADDRESS1 = HY,ADDRESS2 = BA,Fields = {FNAME = ABC,LNAME = XYZ,}}}}
        shop = findViewById(R.id.shop);
        sound = findViewById(R.id.sound);
        //rangAnzeige = findViewById(R.id.ranganzeige);
        start = findViewById(R.id.starten);
        tvhighscore = findViewById(R.id.highscore);
        muenzen = findViewById(R.id.muenzen);

        meingeld = PreferenceManager.getDefaultSharedPreferences(this);

        //Intent intent = getIntent();
        Bundle extras = getIntent().getExtras();
        int score = extras.getInt("SCORE", 0);
        int geld = extras.getInt("MONEY", 0);


        money = meingeld.getInt("KA", 0);

        if (geld > 0) {
            SharedPreferences.Editor editor1 = meingeld.edit();
            editor1.putInt("KA", geld);
            editor1.apply();
            muenzen.setText(Integer.toString(geld));
        }

        int gespeichertesGeld = meingeld.getInt("KA", 0);
        muenzen.setText(Integer.toString(gespeichertesGeld));

        SharedPreferences settings = getSharedPreferences("GAME_DATE", Context.MODE_PRIVATE);
        highScore = settings.getInt("Highscore", 0);
        if (score > highScore) {
            tvhighscore.setText(Integer.toString(score));
            SharedPreferences.Editor editor = settings.edit();
            editor.putInt("Highscore", score);
            editor.apply();
        } else {
            tvhighscore.setText(Integer.toString(highScore));
        }

        mySettings = PreferenceManager.getDefaultSharedPreferences(this);
        sound.setOnCheckedChangeListener(this);

        einstellungenladen();

        start.setOnClickListener(this);
        shop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(MainActivity.this, Shop.class);
                startActivity(intent1);
            }
        });
    }


        public void einstellungenladen() {

            ka = mySettings.getBoolean("SOUND", true);

            if (ka) {
                sound.setChecked(true);
            } else {
                sound.setChecked(false);
            }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            SharedPreferences.Editor editor = mySettings.edit();
            editor.putBoolean("SOUND",true);
            editor.apply();

        }
        else {
            SharedPreferences.Editor editor = mySettings.edit();
            editor.putBoolean("SOUND",false);
            editor.apply();
        }
    }

    @Override
    public void onBackPressed() {

    }

    @Override
    public void onClick(View v) {
        startActivity(new Intent(MainActivity.this, GameActivity.class));
    }

0 个答案:

没有答案