1

此 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;



        }       
    }

}
4

2 回答 2

0

您可能正在使用任何尚未创建的对象。核实...

于 2013-11-08T12:16:44.127 回答
0

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

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

不需要声明 putExtra 键,您可以直接使用它,因为您声明它是 int 确定器

于 2013-07-26T13:21:12.573 回答