weixin_44143858 2019-04-10 22:40 采纳率: 66.7%
浏览 464
已采纳

点击按钮时,程序自动关闭,显示错误

在Android中设置一个按钮,点击按钮跳转至另一个页面。编写完成后,运行不了,点击该按钮,程序自动关闭。求求各位大神帮我看看哪里有问题。

1.这是main.java.里的相关代码
@Override
            public void onClick(View arg0) {
                Intent intent=new Intent(MainActivity.this,TwoActivity.class);
                startActivity(intent);

            }
2.这是two.Java里的代码
package com.jikexueyuan.testqrcode;
import android.app.Activity;
import android.os.Bundle;
public class TwoActivity extends Activity {
 @Override
protected void onCreate(Bundle saveInstanceState){
     super.onCreate(saveInstanceState);
     setContentView(R.layout.two);
 }
}

3.这是main.xml的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jikexueyuan.testqrcode.MainActivity"
    tools:ignore="MergeRootFrame" >

<Button 
       android:id="@+id/gen"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="36dp"
       android:text="生成二维码"
       />
    </LinearLayout>
4.这是two.xml里的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="名片" />

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="短信" />

    <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="文本" />

    <Button
        android:id="@+id/button4"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="电邮" />

</LinearLayout>

  • 写回答

4条回答 默认 最新

  • 萧萧风 2019-04-11 13:49
    关注

    检查activity在AndroidManifest.xml中注册了没

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器