androidruntime java.lang.runtimeexception无法启动活动componentinfo java.lang.classcast异常

时间:2014-02-07 19:05:14

标签: android runtimeexception

该应用无法在模拟器上启动。它提供了许多运行时错误,例如1.androidruntime java.lang.runtimeexception无法启动活动componentinfo java.lang.classcast异常 2.Soundpool无法加载文件等 3.应用程序可能在主线程上做了太多工作。等


以下是MainActivity.java

package com.example.benefitsbuddy;

import java.util.Random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Button a3 = (Button) findViewById(R.id.a3);

    a3.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

         Intent MainActivityIntent = new     Intent(MainActivity.this,checkYourHealth.class);
        startActivity(MainActivityIntent);
        }}  
        );  

    }

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

}

下面的

是checkYourHealth.java

enter code here


package com.example.benefitsbuddy;

//import android.R;
import android.os.Bundle;
import android.app.Activity;
//import android.view.Menu;

public class checkYourHealth extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.checkhealth);
}
}

以下是checkhealth.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:contentDescription="@null"
    android:layout_width="wrap_content"
    android:layout_height="55dp"
    android:src="@drawable/heading2" />

以下是activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="0dp"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/bb"
    android:layout_width="wrap_content"
    android:layout_height="55dp"
    android:layout_alignParentBottom="false"
    android:layout_alignParentLeft="false"
    android:layout_alignParentTop="true"
    android:baselineAlignBottom="false"
    android:clickable="false"
    android:contentDescription="@null"
    android:paddingLeft="0px"
    android:src="@drawable/heading2" />

<ImageButton
    android:id="@+id/a1"
    android:layout_width="95dp"
    android:layout_height="95dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/bb"
    android:layout_marginLeft="60dp"
    android:layout_marginTop="93dp"
    android:paddingLeft="0px"
    android:contentDescription="@null"
    android:src="@drawable/getins" />

<ImageButton
    android:id="@+id/a2"
    android:layout_width="95dp"
    android:layout_height="95dp"
    android:layout_alignTop="@+id/a1"
    android:layout_toRightOf="@+id/a1"
    android:contentDescription="@null"
    android:src="@drawable/freebenefits" />

<ImageButton
    android:id="@+id/a3"
    android:layout_width="95dp"
    android:layout_height="95dp"
    android:layout_below="@+id/a1"
    android:layout_toLeftOf="@+id/a2"
    android:contentDescription="@null"
    android:src="@drawable/checkfree" />

<ImageButton
    android:id="@+id/a4"
    android:layout_width="95dp"
    android:layout_height="95dp"
    android:layout_alignLeft="@+id/a2"
    android:layout_alignTop="@+id/a3"
    android:contentDescription="@null"
    android:src="@drawable/helpperson" />

<ImageButton
    android:id="@+id/a5"
    android:layout_width="60dp"
    android:layout_height="55dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="38dp"
    android:contentDescription="@null"
    android:src="@drawable/howtouse" />

1 个答案:

答案 0 :(得分:0)

使用

  final ImageButton a3 = (ImageButton) findViewById(R.id.a3);

而不是

  final Button a3 = (Button) findViewById(R.id.a3);

因为a3中的ImageButtonButton而不是activity_main.xml