I am new in Android Learning and try to complete my task, in which i need to create the Workout simple app, with dropdown, button and text. In app preview, app is looking fine but when i run on device it gives me an error "Unfortunately, FindWorkOutActivity has stopped working."
I have searched on internet about this error and unable to understand the Logcat information as i didn't learn about this. Kindly help me to solve this error.
Below are the Files of my app:
activity_find_work_out.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.rj.findworkout.FindWorkOutActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/your_workout_here"
android:id="@+id/text_hello"
android:layout_centerHorizontal="true"
android:layout_below="@+id/button_id"
android:layout_marginTop="20dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button_id"
android:text="New Button"
android:layout_centerHorizontal="true"
android:layout_below="@+id/spinner_id"
android:layout_marginTop="20dp" />
<Spinner
android:id="@+id/spinner_id"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="35dp"
android:layout_centerHorizontal="true"
android:entries="@array/work_out"
android:onClick="onClickWorkOut"
>
</Spinner>
</RelativeLayout>
FindWorkOutActivity.java
package com.example.rj.findworkout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Spinner;
import android.widget.TextView;
/**
* Created by Rj on 5/25/2017.
*/
public class FindWorkOutActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_work_out);
}
public void onClickWorkOut(View view){
TextView workouts = (TextView) findViewById(R.id.text_hello);
Spinner workouttype = (Spinner) findViewById(R.id.spinner_id);
String workout = String.valueOf(workouttype.getSelectedItem());
workouts.setText(workout);
}
}