Android 我的应用程序在执行时停止。我的清单有错误吗?
我的应用程序在执行时停止。我开始为android编程,只是放了背景和按钮,但似乎我在创建清单时遇到了问题。在这个项目在创建一个新的eclipse时遇到很多问题之前,我将一个活动与库放在一起,并在这里启动了appcontainer_v7 errenter代码。为了使用SDK 19,我决定手动完成所有操作 类别:Android 我的应用程序在执行时停止。我的清单有错误吗?,android,Android,我的应用程序在执行时停止。我开始为android编程,只是放了背景和按钮,但似乎我在创建清单时遇到了问题。在这个项目在创建一个新的eclipse时遇到很多问题之前,我将一个活动与库放在一起,并在这里启动了appcontainer_v7 errenter代码。为了使用SDK 19,我决定手动完成所有操作 类别: package com.progra.cubebreaker; import android.app.Activity; import android.os.Bundle; import
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>
布局:
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>
清单:
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>
只需替换此代码
Jugar.findViewById(R.id.btJugar);
Puntuaciones.findViewById(R.id.btInstrucciones);
Instrucciones.findViewById(R.id.btInstrucciones);
借
您没有将布局对象映射到您的应用程序正在崩溃的java类对象。 您需要通过将button的id或任何其他属性转换为(button)等来映射java按钮。 修改您的代码:
Jugar = (Button) findViewById(R.id.btInstrucciones);
Puntuaciones= (Button) findViewById(R.id.btPuntuaciones);
Instrucciones = (Button) findViewById(R.id.btInstrucciones);
希望有帮助。您的应用程序正在崩溃,因为您没有初始化代码中的小部件。 以下是错误:
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);
请打印errorIs
按钮
自定义类?我不知道你怎么做Jugar.findviewbyd(R.id.btJugar)代码>并成功编译。我认为在问这个问题之前,你必须学习android基础教程。我希望答案对你有所帮助。