不幸的是,由于ImageButton,我的应用已停止

时间:2014-08-24 17:38:54

标签: android android-intent imagebutton

当我点击图像按钮应用程序停止并显示对话框“不幸的应用程序已停止”。我已经尝试了所有的东西,到处搜索,但无法弄清楚是什么问题。

XML文件          

<ImageButton
    android:id="@+id/ibRoute"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/route" />

<ImageButton
    android:id="@+id/ibStations"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/stations" />

<ImageButton
    android:id="@+id/ibFare"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/fare" />

<ImageButton
    android:id="@+id/ibFeeder"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/feeder" />

<ImageButton
    android:id="@+id/ibParking"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/parking" />

</LinearLayout>

Java文件     包com.myapp.anuj;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class MetroMenu extends Activity implements OnClickListener{

ImageButton b1;
ImageButton b2;
ImageButton b3;
ImageButton b4;
ImageButton b5;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.metromenu);
    b1 = (ImageButton) findViewById(R.id.ibRoute);
    b2 = (ImageButton) findViewById(R.id.ibStations);
    b3 = (ImageButton) findViewById(R.id.ibFare);
    b4 = (ImageButton) findViewById(R.id.ibFeeder);
    b5 = (ImageButton) findViewById(R.id.ibParking);

    b1.setOnClickListener(this);
    b2.setOnClickListener(this);
    b3.setOnClickListener(this);
    b4.setOnClickListener(this);
    b5.setOnClickListener(this);

}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch(arg0.getId()){

    case R.id.ibRoute:
        startActivity(new Intent("com.myapp.anuj.MetroRoute"));
        break;

    case R.id.ibStations:
        Intent openstations = new Intent("com.myapp.anuj.METROSTATIONS");
        startActivity(openstations);
        break;

    case R.id.ibFare:
        Intent openfare = new Intent("com.myapp.anuj.METROFARE");
        startActivity(openfare);
        break;

    case R.id.ibFeeder:
        Intent openfeeder = new Intent("com.myapp.anuj.METROFEEDER");
        startActivity(openfeeder);
        break;

    case R.id.ibParking:

        startActivity(new Intent("com.myapp.anuj.METROPARKING"));
        break;
    }
}

}

App Manifest          

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.myapp.anuj.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAINACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.myapp.anuj.FirstPage"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.myapp.anuj.MetroMenu"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name="com.myapp.anuj.MetroFare"
        android:label="@string/app_name" >

    </activity>
     <activity
        android:name="com.myapp.anuj.MetroParking"
        android:label="@string/app_name" >

    </activity>
     <activity
        android:name="com.myapp.anuj.MetroFeeder"
        android:label="@string/app_name" >

    </activity>
</application>

</manifest>

1 个答案:

答案 0 :(得分:0)

尝试开始这样的新活动:

Intent intent = new Intent(MetroMenu.this, MetroRoute.class);
startActivity(intent);