标题:求大神帮忙,我在编写android时单击button时不能跳转页面。
只看楼主
jianghao2014
Rank: 1
来 自:四川
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-10-10
结帖率:100%
已结贴  问题点数:10 回复次数:3 
求大神帮忙,我在编写android时单击button时不能跳转页面。
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;
    }
 
   
   
   
   
}
搜索更多相关主题的帖子: android package button public import 
2015-05-12 21:28
jianghao2014
Rank: 1
来 自:四川
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-10-10
得分:0 
跳出后出现这个 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)

握不住的沙,不如挥了它
2015-05-12 21:30
ADust、
Rank: 2
等 级:论坛游民
帖 子:21
专家分:57
注 册:2013-1-10
得分:10 
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中注册了么?
2015-05-15 16:03
ADust、
Rank: 2
等 级:论坛游民
帖 子:21
专家分:57
注 册:2013-1-10
得分:0 
名字搞错了吧,一个是LaunchActivity,一个是LandActivity
2015-05-15 16:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-445217-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019090 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved