Reputation: 1
My application is stopped when executed. I'm starting to program for android, just put a background and buttons, but it seems that I have problems creating the manifest. Before this project had many problems creating a new eclipse I put an activity together with the library and I started appcontainer_v7 errenter code hereored. To use the SDK 19 I decided to do everything manually.
CLASS:
package com.progra.cubebreaker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Menu extends Activity implements OnClickListener{
Button Jugar, Puntuaciones, Instrucciones;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
Jugar.setOnClickListener(this);
Puntuaciones.setOnClickListener(this);
Instrucciones.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btJugar:
break;
case R.id.btPuntuaciones:
Toast text = Toast.makeText(this, "Pendiente...", Toast.LENGTH_SHORT);
text.show();
break;
case R.id.btInstrucciones:
Toast text1 = Toast.makeText(this, "Pendiente...", Toast.LENGTH_SHORT);
text1.show();
break;
}
}
}
LAYOUT:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/fondo1" >
<Button
android:id="@+id/btInstrucciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/btPuntuaciones"
android:layout_marginBottom="89dp"
android:text="@string/instrucciones"
android:textSize="40dp"
android:textStyle="italic|normal|bold" />
<Button
android:id="@+id/btPuntuaciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btInstrucciones"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:text="@string/puntuaciones"
android:textSize="40dp"
android:textStyle="italic|normal|bold" />
<Button
android:id="@+id/btJugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btPuntuaciones"
android:layout_centerHorizontal="true"
android:layout_marginBottom="66dp"
android:text="@string/jugar"
android:textColorHint="@android:color/background_dark"
android:textSize="40dp"
android:textStyle="italic|normal|bold" />
</RelativeLayout>
MANIFEST:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.progra.cubebreaker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Upvotes: 0
Views: 75
Reputation: 1039
Your application is crashing as you are not initializing the widgets in your code. Here is the error:
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
Change it to:
Jugar = (Button) findViewById(R.id.btJugar);
Puntuaciones = (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
Upvotes: 0
Reputation: 1050
You are not mapping the layout objects to java class objects thats y ur application is crashing. You need to map the java button by converting id of button or any other attribute to (Button) etc. Modify your code :
Jugar = (Button) findViewById(R.id.btInstrucciones);
Puntuaciones= (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
Hope that helps.
Upvotes: 1
Reputation: 3322
just replace this code,
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
by
Jugar = (Button) findViewById(R.id.btJugar);
Puntuaciones = (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
Upvotes: 0