Click here to Skip to main content
15,883,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Java
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();
            }

        });


    }


}
Posted
Updated 4-Mar-18 2:34am
v2
Comments
Richard MacCutchan 4-Mar-18 9:07am    
You have declared your details class as abstract. Why is this?
David Crow 4-Mar-18 21:32pm    
Have you single stepped through the code using the debugger? You do not have any error checking or try/catch blocks. Why?

1 solution

By using the debugger, you will get an important information: the position where is stops.

There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 
Comments
Kritika Rai 5-Mar-18 1:00am    
Thankyou :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900