android活动中的致命异常

时间:2013-07-26 13:08:04

标签: android android-activity

此Android活动未运行。任何人都可以帮助我。它显示以下错误。 当我点击此按钮开始另一个活动时,它不会运行。

我无法找到此错误。

任何人都可以解决它?

错误: 致命的例外:主要

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testingandroid/com.example.testingandroid.SumsMain}: java.lang.NullPointerException
07-26 12:57:22.958: E/AndroidRuntime(791):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

代码

package com.example.testingandroid;

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

public class SelectTitle extends Activity implements android.view.View.OnClickListener{
public int entryNo;
RadioButton r1;RadioButton r2;RadioButton r3;RadioButton r4;
RadioButton r5;RadioButton r6;RadioButton r7;RadioButton r8;
RadioButton r9;RadioButton r10;RadioButton r11;RadioButton r12;
RadioButton r13;
int determiner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_title);
        r1 = (RadioButton) findViewById(R.id.MasteryPack);
        r2 = (RadioButton) findViewById(R.id.Simplification); 
        r3 = (RadioButton) findViewById(R.id.FractionsandRatios);
        r4 = (RadioButton) findViewById(R.id.Number);
        r5 = (RadioButton) findViewById(R.id.Average);
        r6 = (RadioButton) findViewById(R.id.TimeandWork);
        r7 = (RadioButton) findViewById(R.id.TimeandDistance);
        r8 = (RadioButton) findViewById(R.id.Interest);
        r9 = (RadioButton) findViewById(R.id.Measurement);
        r10 = (RadioButton) findViewById(R.id.Percentage);
        r11 = (RadioButton) findViewById(R.id.BoatandTrain);
        r12 = (RadioButton) findViewById(R.id.Practice);

        r1.setOnClickListener(this);
        r2.setOnClickListener(this);
        r3.setOnClickListener(this);
        r4.setOnClickListener(this);
        r5.setOnClickListener(this);
        r6.setOnClickListener(this);
        r7.setOnClickListener(this);
        r8.setOnClickListener(this);
        r9.setOnClickListener(this);
        r10.setOnClickListener(this);
        r11.setOnClickListener(this);
        r12.setOnClickListener(this);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.select_title, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        case R.id.MasteryPack:
            Intent nextScreen = new Intent(getApplicationContext(), SumsMain.class);

            nextScreen.putExtra("determiner", 1);
            startActivity(nextScreen);
            break;

        case R.id.Simplification:
            Intent nextScreen1 = new Intent(getApplicationContext(), SumsMain.class);
            //String "determiner" = null;
            nextScreen1.putExtra("determiner", 2);
            startActivity(nextScreen1);
            break;

        case R.id.FractionsandRatios:
            Intent nextScreen2 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen2.putExtra("determiner", 3);
            startActivity(nextScreen2);
            break;

        case R.id.Number:
            Intent nextScreen3 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen3.putExtra("determiner", 4);
            startActivity(nextScreen3);
            break;

        case R.id.Average:
            Intent nextScreen4 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen4.putExtra("determiner", 5);
            startActivity(nextScreen4);
            break;

        case R.id.TimeandWork:
            Intent nextScreen5 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen5.putExtra("determiner", 6);
            startActivity(nextScreen5);
            break;

        case R.id.TimeandDistance:
            Intent nextScreen6 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen6.putExtra("determiner", 7);
            startActivity(nextScreen6);
            break;

        case R.id.Interest:
            Intent nextScreen7 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen7.putExtra("determiner", 8);
            startActivity(nextScreen7);
            break;

        case R.id.Measurement:
            Intent nextScreen8 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen8.putExtra("determiner", 9);
            startActivity(nextScreen8);
            break;

        case R.id.Percentage:
            Intent nextScreen9 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen9.putExtra("determiner", 10);
            startActivity(nextScreen9);
            break;

        case R.id.BoatandTrain:
            Intent nextScreen10 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen10.putExtra("determiner", 11);
            startActivity(nextScreen10);
            break;

        case R.id.Practice:
            Intent nextScreen11 = new Intent(getApplicationContext(), SumsMain.class);
            nextScreen11.putExtra("determiner", 12);
            startActivity(nextScreen11);
            break;



        }       
    }

}

2 个答案:

答案 0 :(得分:0)

要从一个活动转移到另一个活动,我们通常使用Intents,我们必须在其中写下我们想要移动的类Activity的名称。

在代码中,您必须在运行代码之前创建SumMain类。

无需声明putExtra键,您可以在声明时直接使用它 int determininer

答案 1 :(得分:0)

您可能正在使用尚未创建的任何对象。检查一下......