2014-10-27 2 views
0

Мое приложение останавливается при выполнении. Я начинаю программировать для android, просто помещаю фон и кнопки, но кажется, что у меня проблемы с созданием манифеста. Перед этим проектом было много проблем с созданием нового затмения. Я поместил свою деятельность вместе с библиотекой, и я начал использовать здесь код errenter-кода appcontainer_v7. Чтобы использовать SDK 19, я решил сделать все вручную.Мое приложение останавливается при его исполнении. Ошибка в моем манифесте?

КЛАСС:

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; 

    } 

} 

} 

ВИД:

<?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 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> 
+0

Распечатайте ошибку –

+1

ли 'Button' пользовательский класс? Я не вижу, как вы можете сделать Jugar.findViewById (R.id.btJugar); 'и успешно скомпилировать его. – LightYearsBehind

+0

Я думаю, прежде чем задавать этот вопрос, вам нужно научиться из основного учебника по Android. –

ответ

0

просто заменить этот код,

Jugar.findViewById(R.id.btJugar); 
    Puntuaciones.findViewById(R.id.btInstrucciones); 
    Instrucciones.findViewById(R.id.btInstrucciones); 

по

 Jugar = (Button) findViewById(R.id.btJugar); 
     Puntuaciones = (Button) findViewById(R.id.btPuntuaciones); 
     Instrucciones = (Button) findViewById(R.id.btInstrucciones); 
1

Вы не отображения объектов компоновки для класса объектов Java Thats у ур приложение разбивая. Вам необходимо отобразить кнопку Java путем преобразования идентификатор кнопки или любого другого атрибута (Button) и т.д. Изменить код:

Jugar = (Button) findViewById(R.id.btInstrucciones); 
Puntuaciones= (Button) findViewById(R.id.btPuntuaciones); 
Instrucciones = (Button) findViewById(R.id.btInstrucciones); 

Надежда, что помогает.

+0

Массаб! Здравствуй. Просто делаю преследование стены ....... –

+0

Надеюсь, ответ вам помог. – Massab

+0

nop. Это не так. –

0

Ваше приложение разбивается, поскольку вы не инициализируете виджетов вашего кода. Здесь ошибка:

Jugar.findViewById(R.id.btJugar); 
Puntuaciones.findViewById(R.id.btInstrucciones); 
Instrucciones.findViewById(R.id.btInstrucciones); 

Изменить это:

Jugar = (Button) findViewById(R.id.btJugar); 
Puntuaciones = (Button) findViewById(R.id.btPuntuaciones); 
Instrucciones = (Button) findViewById(R.id.btInstrucciones); 
Смежные вопросы