package com.example.darshreddy.diser;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class SQLite extends Activity {
Button but;
EditText nam, mail, pass;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
nam = (EditText) findViewById(R.id.name);
pass = (EditText) findViewById(R.id.passw);
mail = (EditText) findViewById(R.id.emi);
but = (Button) findViewById(R.id.button2);
but.setOnClickListener((View.OnClickListener) this);
}
public void onClick(View arg0){
switch (arg0.getId()) {
case R.id.button2:
boolean didItwork=true;
try {
String name = nam.getText().toString();
String passw = pass.getText().toString();
String eml = mail.getText().toString();
SQL entry = new SQL(SQLite.this);
entry.open();
entry.createEntry(name, passw, eml);
entry.close();
} catch (Exception e) {
didItwork=false;
}finally {
if (didItwork) {
Dialog d = new Dialog(this);
d.setTitle("Heck yea!!");
TextView tv = new TextView(this);
tv.setText("success");
d.setContentView(tv);
d.show();
}
}
break;}
}
}
这是我为执行SQLite
数据库相关文件而编写的代码。我有
将注册链接到它并且错误是#34;不幸的是,应用程序已停止"。请帮我找到错误,如果有的话。或者建议我做一些改变。
logcat显示
" java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.darshreddy.diser / com.example.darshreddy.diser.SQLite}:java.lang.ClassCastException:com.example.darshreddy。 diser.SQLite无法强制转换为android.view.View $ OnClickListener"
答案 0 :(得分:0)
您需要实现OnClickListener
界面,如:
public class SQLite extends Activity implements View.OnClickListener {
另外,按照@Brett Jeffreson的建议在e.printStackTrace()
中添加catch block
以获取日志中的错误/崩溃跟踪