【发布时间】:2016-10-12 16:17:04
【问题描述】:
这是在此方法中调用 Appdata() 的 oncreate 函数
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();
}
}
);
}
在 Appdata 函数中创建了 OnClickListener(),但我的问题是当我运行此程序时,应用程序会停止并重新启动
当我隐藏在 Appdata() 程序的代码中时,它的运行没有任何错误
我上传了图片click here
【问题讨论】:
-
发布您在 Android 监视器上看到的错误消息
-
不...它只在模拟器中显示“应用程序不断停止”
-
您在 Android 监视器上看不到故障转储?
-
no..我试图将 onclicklistener 放入 OnCreate() 但它不起作用
-
发布你的activity_main.xml
标签: sqlite android-studio onclicklistener