注册 登录
编程论坛 Android开发

求大神帮忙,我在编写android时单击button时不能跳转页面。

jianghao2014 发布于 2015-05-12 21:28, 3476 次点击
package com.example.gclion2;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
   
   
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Button btn1=(Button)findViewById(R.id.btnLoad);
        Button  btn2=(Button)findViewById(R.id.btnExit);
        //跳转到登陆界面
        btn1.setOnClickListener(new OnClickListener()
        {  public void onClick(View v)
             {
                 Intent intent=new Intent(MainActivity.this, LandActivity.class);
                MainActivity.this.startActivity(intent);
                MainActivity.this.finish();
             }   
   
        });  
 
        //退出
        btn2.setOnClickListener(new OnClickListener()
        {
             public void onClick(View v)
             {
                 MainActivity.this.finish();  //关闭页面
             }  
           
         });
        
        
     // new Handler().postDelayed(new Runnable(){
        //        public void run() {
                    // TODO Auto-generated method stub
          //           Intent intent = new Intent(MainActivity.this, LandActivity.class);
            //         startActivity(intent);
             //        MainActivity.this.finish();
                  
             //    }
         //}, 2000);//两秒后跳转到内容页
      
        
  
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
   
   
   
   
}
3 回复
#2
jianghao20142015-05-12 21:30
跳出后出现这个 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
#3
ADust、2015-05-15 16:03
package com.example.qwe.activity;

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

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn1=(Button)findViewById(R.id.btnLoad);
        Button  btn2=(Button)findViewById(R.id.btnExit);
        //跳转到登陆界面
        btn1.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View arg0) {
              Intent intent=new Intent(MainActivity.this, LandActivity.class);
              MainActivity.this.startActivity(intent);
              MainActivity.this.finish();
               
            }
        });
        //退出
        btn2.setOnClickListener(new OnClickListener()
        {
             public void onClick(View v)
             {
                 MainActivity.this.finish();  //关闭页面
             }  
           
         });
        
        
     // new Handler().postDelayed(new Runnable(){
        //        public void run() {
                    // TODO Auto-generated method stub
          //           Intent intent = new Intent(MainActivity.this, LandActivity.class);
            //         startActivity(intent);
             //        MainActivity.this.finish();
                  
             //    }
         //}, 2000);//两秒后跳转到内容页
      
        
  
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }   
}


我运行了一遍,没出错阿,
楼主的LandActivity在AndroidManifast中注册了么?
#4
ADust、2015-05-15 16:04
名字搞错了吧,一个是LaunchActivity,一个是LandActivity
1