带开始活动的页面切换(按钮单击)

时间:2014-05-07 15:16:12

标签: java android eclipse start-activity

我尝试用按钮实现不同活动之间的简单切换。调试后我收到了这条消息。我该如何解决?

Meine_Konfiguration [Android Application]   
DalvikVM [localhost:8615]   
    Thread [<1> main] (Suspended (exception RuntimeException))  
        <VM does not provide monitor information>   
        ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2211    
        ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2261 
        ActivityThread.access$600(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 141    
        ActivityThread$H.handleMessage(Message) line: 1256  
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 137 
        ActivityThread.main(String[]) line: 5103    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 525  
        ZygoteInit$MethodAndArgsCaller.run() line: 737  
        ZygoteInit.main(String[]) line: 553 
        NativeStart.main(String[]) line: not available [native method]  
    Thread [<10> Binder_2] (Running)    
    Thread [<9> Binder_1] (Running) 

这些是我的进口商品:

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.TextView;
import android.view.View;
import android.util.Log;

这是我的MainActivity.class:

public class MainActivity extends Activity {

private Button ButtonBar;
private Button ButtonRes;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ButtonBar = (Button) findViewById(R.id.barBTN);
    ButtonRes = (Button) findViewById(R.id.resBTN);

    ButtonBar.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent barIntent = new Intent(MainActivity.this, BarListActivity.class);
            startActivity(barIntent);      
            //finish();
        }
    });


    ButtonRes.setOnClickListener (new View.OnClickListener() {
        public void onClick(View v) {
            Intent resIntent = new Intent(MainActivity.this, RestaurantListActivity.class);
            startActivity(resIntent);
            //finish();
        }
    });

}

感谢您的帮助

0 个答案:

没有答案