0

The app fails to launch on the emulator. it is giving many run time errors such as 1.androidruntime java.lang.runtimeexception unable to start activity componentinfo java.lang.classcast exception 2.Soundpool cannot load file etc. 3.The application may be doin too much work on the main thread. etc


Below is 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;
}

}

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

Below is 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" />

Below is 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 Answers1

0

Use

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

instead of

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

because a3 is ImageButton instead of Button in activity_main.xml

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213