D
D
Denis2017-04-25 00:00:00
Android
Denis, 2017-04-25 00:00:00

Why does an Android app crash when switching to a new Activity?

Hello!
The application has 5 menu items. When clicked, a transition to a new window takes place. When switching to the calculator, the application gives an error and closes. Previously, everything worked - added the code, and then it started. I commented out the added lines - it did not help. Tell me, what could be the reason? Here are the files.

package com.example.fitness_application;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
 * Created by Денис on 28.02.2017.
 */
public class ActivityCalc extends AppCompatActivity {

    private TextView Sum = (TextView) findViewById(R.id.textView9);
    public static final String APP_PREFERENCES = "mysettings";
    public static final String APP_PREFERENCES_SUM = "Sum"; // сумма в калькуляторе
    SharedPreferences mSettings;
    private double a, b, c, d;
    private double n = 0;

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

//        mSettings = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
//
//        String strNickName = Sum.getText().toString();
//
//        SharedPreferences.Editor editor = mSettings.edit();
//        editor.putString(APP_PREFERENCES_SUM, strNickName);
//        editor.apply();
    }

    public void ClickMilk(View view) {
       a = 60;
       n = n + a;
       String N = Double.toString(n);
       Sum.setText(N);
    }

    public void ClickChick(View view) {
        b = 200;
        n = n + b;
        String N = Double.toString(n);
        Sum.setText(N);
    }

    public void ClickBuckwheat(View view) {
        c = 132;
        n = n + c;
        String N = Double.toString(n);
        Sum.setText(N);
    }

    public void ClickPaste(View view) {
        d = 588;
        n = n + d;
        String N = Double.toString(n);
        Sum.setText(N);
    }

//    public void ClickNewProd(View view) {
//
//    }

}

acf4e0eead5541c4b6745dc406dff7e6.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2017-04-25
@red-barbarian

because in the R.layout.activity_calc layout there are buttons that have a method described in the onClick field that is not in ActivityCalc.
look for the error in activity_calc.xml

K
K0DiBEN, 2017-04-25
@K0DiBEN

Step 1: Clean your project by clicking Project -> Clean.
Step 2: Rebuild your project by clicking Project -> Build All.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question