未知异常android

未知异常android,android,Android,这是我的主文件,它有图像按钮,它给了我一个例外。当我点击课程图像按钮时,它只是关闭应用程序 它适用于其余按钮(rest活动仅包括文本视图和按钮),而在课程视图中,我又添加了3个按钮(在添加这3个按钮之前,它用于在主课程和课程之间切换) 我想做的是: 在课程活动中制作3个按钮。他们会引导我转向其他观点,如“高等教育”或“继续教育”。在接下来的视图中,我将创建一个显示课程名称的列表(如“CCNA”或“健康文凭”!)。当用户单击课程时,它将显示有关课程的图片和一些文本信息 package com.NV

这是我的主文件,它有图像按钮,它给了我一个例外。当我点击课程图像按钮时,它只是关闭应用程序

它适用于其余按钮(rest活动仅包括文本视图和按钮),而在课程视图中,我又添加了3个按钮(在添加这3个按钮之前,它用于在主课程和课程之间切换)

我想做的是:

在课程活动中制作3个按钮。他们会引导我转向其他观点,如“高等教育”或“继续教育”。在接下来的视图中,我将创建一个显示课程名称的列表(如“CCNA”或“健康文凭”!)。当用户单击课程时,它将显示有关课程的图片和一些文本信息

package com.NVT.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class Main extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ImageButton CoursesButton = (ImageButton)findViewById(R.id.CoursesButton);
        ImageButton ILoveNescotButton = (ImageButton)findViewById(R.id.ILoveNescotButton);
        ImageButton CampusMapButton = (ImageButton)findViewById(R.id.CampusMapButton);
        ImageButton GettingHereButton = (ImageButton)findViewById(R.id.GettingHereButton);

        CoursesButton.setOnClickListener(new ImageButton.OnClickListener()
        {

            @Override
            public void onClick(View view) 
            {
                            Intent myIntent = new Intent(view.getContext(), Courses.class);
                            startActivityForResult(myIntent, 0);
            }

        });

        ILoveNescotButton.setOnClickListener(new ImageButton.OnClickListener()
        {

            @Override
            public void onClick(View view) 
            {
                            Intent myIntent = new Intent(view.getContext(), ILoveNescot.class);
                            startActivityForResult(myIntent, 0);
            }

        });

        CampusMapButton.setOnClickListener(new ImageButton.OnClickListener()
        {

            @Override
            public void onClick(View view) 
            {
                            Intent myIntent = new Intent(view.getContext(), CampusMap.class);
                            startActivityForResult(myIntent, 0);
            }

        });

        GettingHereButton.setOnClickListener(new ImageButton.OnClickListener()
        {

            @Override
            public void onClick(View view) 
            {
                            Intent myIntent = new Intent(view.getContext(), GettingHere.class);
                            startActivityForResult(myIntent, 0);
            }

        });

    }
}
课程视图“Courses.java”的代码如下所示

package com.NVT.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

    public class Courses extends Activity 
    {

        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.courses);


            Button ButtonFurtherEducation = (Button)findViewById(R.id.Button_Courses_FurtherEducation);
            Button ButtonHigherEducation = (Button)findViewById(R.id.Button_Courses_HigherEducation);
            Button ButtonEmployernTraining = (Button)findViewById(R.id.Button_Courses_EmployersnTraining);
            Button next = (Button) findViewById(R.id.Button01);


            ButtonFurtherEducation.setOnClickListener(new Button.OnClickListener()
            {

                @Override
                public void onClick(View view) 
                {
                                Intent myIntent = new Intent(view.getContext(), FurtherEducationCourses.class);
                                startActivityForResult(myIntent, 0);
                }

            });


            ButtonHigherEducation.setOnClickListener(new Button.OnClickListener()
            {

                @Override
                public void onClick(View view) 
                {
                                Intent myIntent = new Intent(view.getContext(), HigherEducationCourses.class);
                                startActivityForResult(myIntent, 0);
                }

            });

            ButtonEmployernTraining.setOnClickListener(new Button.OnClickListener()
            {

                @Override
                public void onClick(View view) 
                {
                                Intent myIntent = new Intent(view.getContext(), EmployersTrainingCourses.class);
                                startActivityForResult(myIntent, 0);
                }

            });



            next.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View view) 
                {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });
        }   
    }
package com.NVT.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

    public class FurtherEducationCourses extends Activity 
    {

        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.further_education);

            Button next = (Button) findViewById(R.id.Button01);
            next.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View view) 
                {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });
        }   
    }
继续教育活动的代码如下所示

package com.NVT.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

    public class Courses extends Activity 
    {

        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.courses);


            Button ButtonFurtherEducation = (Button)findViewById(R.id.Button_Courses_FurtherEducation);
            Button ButtonHigherEducation = (Button)findViewById(R.id.Button_Courses_HigherEducation);
            Button ButtonEmployernTraining = (Button)findViewById(R.id.Button_Courses_EmployersnTraining);
            Button next = (Button) findViewById(R.id.Button01);


            ButtonFurtherEducation.setOnClickListener(new Button.OnClickListener()
            {

                @Override
                public void onClick(View view) 
                {
                                Intent myIntent = new Intent(view.getContext(), FurtherEducationCourses.class);
                                startActivityForResult(myIntent, 0);
                }

            });


            ButtonHigherEducation.setOnClickListener(new Button.OnClickListener()
            {

                @Override
                public void onClick(View view) 
                {
                                Intent myIntent = new Intent(view.getContext(), HigherEducationCourses.class);
                                startActivityForResult(myIntent, 0);
                }

            });

            ButtonEmployernTraining.setOnClickListener(new Button.OnClickListener()
            {

                @Override
                public void onClick(View view) 
                {
                                Intent myIntent = new Intent(view.getContext(), EmployersTrainingCourses.class);
                                startActivityForResult(myIntent, 0);
                }

            });



            next.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View view) 
                {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });
        }   
    }
package com.NVT.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

    public class FurtherEducationCourses extends Activity 
    {

        /** Called when the activity is first created. */
        public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.further_education);

            Button next = (Button) findViewById(R.id.Button01);
            next.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View view) 
                {
                    Intent intent = new Intent();
                    setResult(RESULT_OK, intent);
                    finish();
                }

            });
        }   
    }
我的舱单编码如下

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.NVT.android"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">

        <activity android:name=".Main"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <activity android:name=".Courses">
        </activity>
        <activity android:name=".CampusMap">
        </activity>
        <activity android:name=".GettingHere">
        </activity>
        <activity android:name=".ILoveNescot">
        </activity>


        <activity android:name=".FurtherEducationCourses">
        </activity>
        <activity android:name=".HigherEducationCourses">
        </activity>
        <activity android:name=".EmployersTrainingCourses">
        </activity>







    </application>
    <uses-sdk android:minSdkVersion="9" />

</manifest> 


根据logcat屏幕截图,您的问题是按钮next为空,因为它是第63行中的
NullPointerException
,此时您调用
next.setOnClickListener
,这意味着
R.id.Button01
不在
R.layout.courses
,您能否验证此信息是否正确?

您将在logcat屏幕中看到,应用程序中带有类名的第一行是“Courses.java”。因此,错误就发生在那里。在logcat中,您将在Courses.java第63行看到NullPointerException。在Courses.java的第63行中,您已经为next按钮设置了onclick侦听器。因此,我认为当这行执行时,next按钮保持为空。我认为主要错误在第21行

Button next = (Button) findViewById(R.id.Button01);
我认为布局文件(corses.xml)中的next按钮的id不是Button01。请解决这个问题,这样就不会有错误了


试试看。:)

您也可以添加您得到的异常。它只是关闭应用程序,当我单击courses按钮时,我说“强制关闭”或其他什么…我认为问题始于“Intent myIntent=newintent(view.getContext(),courses.class);”听起来像是一个典型的问题,您没有在AndroidManifest.xml中指定新活动file@Tom:当DDMS强制关闭时,请给出日志输出。那么也许我们就能很容易地找到错误了;我不明白,我进入R.java文件,查看“公共静态最终类id”,发现这个“公共静态最终int Button01=0x7f050002;”所以我想它就在那里,请引导你有一个名为courses的文件,它是一个布局,在它里面,你有按钮按钮按钮按钮按钮按钮按钮按钮“课程”\u继续教育,按钮按钮“课程”\u高等教育,按钮、课程、员工培训;nut似乎Button01未在该文件中声明;因此,在使用findViewById(R.id.Button01)时返回null;因此,要么以不同的名称命名,要么没有添加到文件中。让我知道你发现了什么是的,这就是问题所在,我可以查看课程,但现在不进入继续教育窗口,如果可以,请指导,非常感谢吉普赛人:DDoS它是否显示与课程相同的错误。java?在继续教育中,下一步按钮使用的代码与courses.java相同。如果没有问题,那么单击“下一步”按钮是否有问题?那么,我认为问题就在这里:Intent=newintent();设置结果(结果正常,意图);完成();使用以下代码代替上述代码:setResult(RESULT_OK);完成();这是同样的button01问题,在FutureEducation.xml文件中,非常感谢您的时间,如果需要更多帮助,我会回来,谢谢,我要问一个关于android选项卡活动的新问题,再次感谢:)然后请投票表决我的答案,如果答案正确,然后将答案标记为正确。谢谢,我能做吗,请导游