Answer the question
In order to leave comments, you need to log in
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) {
//
// }
}
Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question