Javascript Can';t run my app表示应用程序已停止

Javascript Can';t run my app表示应用程序已停止,javascript,android,xml,android-intent,Javascript,Android,Xml,Android Intent,我正在制作一个简单的应用程序,它使用一个数学技巧来了解人们的想法(技巧),但当我尝试运行它时,它会停止并崩溃,而它永远不会启动,这是我的主要活动 public class MainActivity extends Activity { Button btnn; Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

我正在制作一个简单的应用程序,它使用一个数学技巧来了解人们的想法(技巧),但当我尝试运行它时,它会停止并崩溃,而它永远不会启动,这是我的主要活动

public class MainActivity extends Activity {
 Button btnn;
 Button btn; 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(android.R.style.Theme_DeviceDefault);
    setContentView(R.layout.activity_main);
     btnn= (Button) findViewById(R.id.Start);
     btn= (Button) findViewById(R.id.Exit);
     btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setMessage("Are you sure you want to exit?");
        //  builder.setCancelable(false);
            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    MainActivity.this.finish();
                }
            });
            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });
    btnn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent toNextPage = new Intent(MainActivity.this,
                    two.class); 
            startActivity(toNextPage);
            MainActivity.this.finish();

        }
    }); 
}}
这是我的xml文件

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to Brain Reader"
        android:textAppearance="?android:attr/textAppearanceLarge"
          android:textStyle="bold"
          android:layout_marginLeft="16dp"
    android:typeface="serif" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium" 
          android:textStyle="bold"
          android:textSize="22dp"
    android:typeface="serif"/>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/Start"
            android:layout_width="110dp"
            android:layout_height="50dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_launche"
            android:layout_marginLeft="10dp" />

        <ImageButton
            android:id="@+id/Exit"
            android:layout_width="110dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ex"
            android:layout_marginRight="10dp" />

    </RelativeLayout>

</LinearLayout>

将按钮更改为ImageButton,而不是:

btnn= (Button) findViewById(R.id.Start);
btn= (Button) findViewById(R.id.Exit);
使用:


请将您的图像按钮更改为XML文件中的按钮

在Java类中将按钮更改为ImageButton

ImageButton btnn;
ImageButton btn; 

btnn= (ImageButton) findViewById(R.id.Start);
btn= (ImageButton) findViewById(R.id.Exit);

如果缺少此步骤,请执行以下操作: 检查您的Android-Manifest.xml,如果您没有找到MainActivity的条目,请添加以下内容:

<activity
            android:name=".MainActivity"
            android:label="@string/any_string">
</activity>


如果它适合您….

您正在将ImageButton强制转换为按钮类型。你这样做是不对的。
应为ImageButton类型。

只需将代码中的按钮更改为ImageButton即可。

能否检查日志并提供有关错误的更多信息。
ImageButton btnn;
ImageButton btn; 

btnn= (ImageButton) findViewById(R.id.Start);
btn= (ImageButton) findViewById(R.id.Exit);
<activity
            android:name=".MainActivity"
            android:label="@string/any_string">
</activity>