Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7196

ToggleButton prevents my app from starting

$
0
0

I am making a calculator for a minigame, everything worked fine until I added a toggleButton. The app crashes on start, but I could not find any errors.

JAVA code:

.
.
.    
    int colorOff = getResources().getColor(R.color.toggleOff);
    int colorOn = getResources().getColor(R.color.toggleOn);

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

//This method is supposed to change the color of the toggle button when it is checked and not checked.
    public void seraA(View view) {
        ToggleButton seraToggle = (ToggleButton) findViewById(R.id.sera_toggle);
            if (seraToggle.isChecked()) {
                seraToggle.setBackgroundColor(colorOn); }
            else
                seraToggle.setBackgroundColor(colorOff);
    }
.
.
.

XML code:

.
.
.
<ToggleButton
    android:id="@+id/sera_toggle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="8dp"
    android:layout_marginVertical="4dp"
    android:onClick="seraA"
    android:textOn="@string/sera_T"
    android:textOff="@string/sera_T"
    android:textColor="#E0F7FA"
    android:textSize="20sp" />
.
.
.

Viewing all articles
Browse latest Browse all 7196

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>