Sqlite OnClickListener()不';I don’我不允许启动这个程序

Sqlite OnClickListener()不';I don’我不允许启动这个程序,sqlite,android-studio,onclicklistener,Sqlite,Android Studio,Onclicklistener,这是一个oncreate函数,我在这个方法中调用Appdata() protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db=new DatabaseHelper(this); Toolbar toolbar = (Toolbar) findView

这是一个oncreate函数,我在这个方法中调用Appdata()

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
      db=new DatabaseHelper(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    email=(EditText)findViewById(R.id.editText4);
    pass=(EditText)findViewById(R.id.editText5);
    conpass=(EditText)findViewById(R.id.editText6);
    register=(Button)findViewById(R.id.btn_register);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    AddData();
}

public  void AddData() {
    register.setOnClickListener(
                new View.OnClickListener() {

                public void onClick(View v) {
                            boolean isInserted = db.insertData(email.getText().toString(),pass.getText().toString(), conpass.getText().toString());
                          if(isInserted == true)
                         Toast.makeText(MainActivity.this,"Data Inserted",Toast.LENGTH_LONG).show();
                         else
                        Toast.makeText(MainActivity.this,"Data not Inserted",Toast.LENGTH_LONG).show();
                }
            }
    );

}
已创建In-Appdata函数,但我的问题是当我运行此程序时,应用程序变为停止并重新启动
当我隐藏在Appdata()程序的代码中时,它运行时不会出现任何错误
我上传了图像

您的xml文件中不存在id为R.id.btn_寄存器的按钮这会在您尝试设置单击侦听器时导致NullPointerException。在xml布局中添加按钮和编辑文本,就可以开始了

在activity_main.xml中添加以下代码

<include
     layout= "@layout/your_extra_layout_file"/>

发布您在Android监视器上看到的错误消息否…它只在模拟中显示“应用程序一直停止”您在Android监视器上没有看到崩溃转储?否…我试图将onclicklistener放在OnCreate()中,但它不起作用发布您的活动\u main.xml它起作用。。。但是,假设我想在我的额外布局中编写(onclicklistener())代码,如何做到这一点?这会发生另一个设计过载到“活动”\u main我将我的AddData()放在我的\u extra\u布局中,但当我单击“寄存器”(按钮)时出现问题
public void function_name(View view) {
     //do the action here
}