“不幸的是,该应用程序已停止工作” [英] "Unfortunately the app has stopped working"

查看:93
本文介绍了“不幸的是,该应用程序已停止工作”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码有什么问题?它说不幸的是应用程序已经停止工作。我想不通请帮帮我。我是android的新手,所以不太了解它。



我尝试了什么:



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

        });


    }


}

推荐答案

通过使用调试器,您将获得一个重要信息:停止的位置。



有一个工具可以让你看到你的代码正在做什么,它的name是调试器。它也是一个很好的学习工具,因为它向你展示了现实,你可以看到哪种期望与现实相符。

当你不明白你的代码在做什么或为什么它做它做的时候,答案就是答案是调试器

使用调试器查看代码正在执行的操作。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

HTTP://docs.or acle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你到。当代码没有达到预期的效果时,你就会接近一个错误。
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.


这篇关于“不幸的是,该应用程序已停止工作”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆