What's wrong with the code? It says "Unfortunately the app has stopped working". I can't figure out please help me. I am new to android so don't know much about it.
What I have tried:
package com.kritikafunmath.helpquest;
import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public abstract class details extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
Spinner s1, s2, s3;
String[] school_name = {"School of Computer Application", "School of Civil Engineering", "School of Computer Engineering",
"School of Electrical Engineering", "School of Electronics Engineering",
"School of Mechanical Engineering", "School of Humanities and Social Sciences", "School of Applied Sciences",
"School of Management", "School of Biotechnology", "School of Rural Management", "School of Law",
"School of Fashion Technology", "School of Film and Media Sciences", "School of Medicine"};
int spinschool;
int spindegree;
Button b1;
void populateDeg() {
if (spinschool > 1 && spinschool < 7) {
String[] engineering = {"BTech","MTech"};
ArrayAdapter a = new ArrayAdapter(this, android.R.layout.simple_spinner_item, engineering);
a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(a);
}
}
void populateYear(){
if (spindegree == 1) {
String[] btech = {"First", "Second", "Third", "Fourth"};
ArrayAdapter b = new ArrayAdapter(this, android.R.layout.simple_spinner_item, btech);
b.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s3.setAdapter(b);
}
else if (spindegree == 2) {
String[] mtech = {"First", "Second"};
ArrayAdapter c = new ArrayAdapter(this, android.R.layout.simple_spinner_item, mtech);
c.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s3.setAdapter(c);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
Toast.makeText(this, "Please select the School, Academic Degree and Academic Year in order to continue", Toast.LENGTH_LONG).show();
ActionBar ab = getSupportActionBar();
ab.setDisplayUseLogoEnabled(true);
s1 = (Spinner) findViewById(R.id.spinner1);
s2 = (Spinner) findViewById(R.id.spinner2);
s3 = (Spinner) findViewById(R.id.spinner3);
b1 = (Button) findViewById(R.id.b1);
s1.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, school_name);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(aa);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(details.this, subject.class);
startActivity(i);
}
});
s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String school = (String) parent.getItemAtPosition(position);
if (school.matches("School of Computer Appication")) {
spinschool = 1;
populateDeg();
;
} else if (school.matches("School of Civil Engineering")) {
spinschool = 2;
populateDeg();
} else if (school.matches("School of Computer Engineering")) {
spinschool = 3;
populateDeg();
} else if (school.matches("School of Electrical Engineering")) {
spinschool = 4;
populateDeg();
} else if (school.matches("School of Electronics Engineering")) {
spinschool = 5;
populateDeg();
} else if (school.matches("School of Mechanical Engineering")) {
spinschool = 6;
populateDeg();
} else if (school.matches("School of Humanities and Social Sciences")) {
spinschool = 7;
populateDeg();
} else if (school.matches("School of Applied Sciences")) {
spinschool = 8;
populateDeg();
} else if (school.matches("School of Management")) {
spinschool = 9;
populateDeg();
} else if (school.matches("School of Biotechnology")) {
spinschool = 10;
populateDeg();
} else if (school.matches("School of Rural Management")) {
spinschool = 11;
populateDeg();
} else if (school.matches("School of Law")) {
spinschool = 12;
populateDeg();
} else if (school.matches("School of Fashion Technology")) {
spinschool = 13;
populateDeg();
} else if (school.matches("School of Film and Media Sciences")) {
spinschool = 14;
populateDeg();
} else if (school.matches("School of Medicine")) {
spinschool = 15;
populateDeg();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(details.this, "Please select the School to which subject belongs", Toast.LENGTH_LONG).show();
}
});
s2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String degree = (String) parent.getItemAtPosition(position);
if (degree.matches("BTech") && (spinschool > 1 && spinschool < 7)) {
spindegree = 1;
populateYear();
} else if (degree.matches("MTech") && (spinschool > 1 && spinschool < 7)) {
spindegree = 2;
populateYear();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(details.this, "Please select the Academic Degree to continue", Toast.LENGTH_LONG).show();
}
});
}
}