gpt4 book ai didi

android - 未知异常安卓

转载 作者:行者123 更新时间:2023-11-29 00:48:19 24 4
gpt4 key购买 nike

这是我的主文件,它有图像按钮,它给了我一个异常(exception)。当我点击类(class)图像按钮时,它只是关闭应用程序。

它适用于其余按钮(休息 Activity 仅包含一个 TextView 和按钮),而在类(class) View 中,我又添加了 3 个按钮(在我添加这 3 个按钮之前,它用于在主要和类(class)之间切换)。

我想做的是:

在类(class) Activity 中制作 3 个按钮。他们会将我引导到其他观点,如“高等教育”或“继续教育”。在接下来的 View 中,我将创建一个显示类(class)名称的列表(例如“CCNA”或“健康文凭”!)。当用户点击类(class)时,会显示类(class)的图片和一些文字信息。

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

});

}
}

类(class) View “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();
}

});
}
}

继续教育 Activity 的代码如下,,,,

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

});
}
}

我的 list 编码如下

<?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 屏幕中看到您的应用程序中带有类名的第一行是“Courses.java”。所以,错误发生在那里。在 logcat 中,您将在 Courses.java 的第 63 行看到 NullPointerException。在 Courses.java 的第 63 行中,您已经为下一步按钮设置了 onclick 监听器。所以,我认为下一个按钮在执行此行时保持为空。我认为主要错误在第 21 行

Button next = (Button) findViewById(R.id.Button01);

我认为布局文件(corses.xml)中下一个按钮的id 不是Button01。请修复此问题,然后不会有错误。

试试吧。 :)

关于android - 未知异常安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4991635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com