类转换异常我用这个构造函数来创建一个数据库,当一个按钮被点击这将调用构造函数,当我运行它显示java.lang.ClasscastException错误我的类型转换onClickListener是正确与否请人建议当按钮点击我称为构造函数显示在android
private static Context onClickListene;
public DatabaseHandler3(OnClickListener onClickListene)
{
super((Context) onClickListene,DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
这是调用程序构造
button2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
try
{
final EditText edittxt4 = (EditText)findViewById(R.id.editText4);
final EditText edittxt5 = (EditText)findViewById(R.id.editText5);
final EditText edittxt6 = (EditText)findViewById(R.id.editText6);
String name=edittxt4.getText().toString();
String mailfamfri=edittxt5.getText().toString();
String phonefamfri=edittxt6.getText().toString();
int famatpos=mailfamfri.indexOf("@");
int famdotpos=mailfamfri.lastIndexOf(".");
int phonecount=phonefamfri.length();
if(name.equals(""))
{
Toast.makeText(FiveActivity.this, "You Family or Friends name is empty",Toast.LENGTH_LONG).show();
}
else if(mailfamfri.equals(""))
{
Toast.makeText(FiveActivity.this, "You Families or Friend's Mail-ID is Empty",Toast.LENGTH_LONG).show();
}
else if(famatpos<1 || famdotpos=mailfamfri.length())
{
Toast.makeText(FiveActivity.this, "You Families or Friend's Email-ID is not valid",Toast.LENGTH_LONG).show();
}
else if(phonefamfri.equals(""))
{
Toast.makeText(FiveActivity.this, "Phone Number is empty",Toast.LENGTH_LONG).show();
}
else if(phonefamfri.contains("[a-zA-z]"))
{
Toast.makeText(FiveActivity.this, "Phone Number should not contain any letters ",Toast.LENGTH_LONG).show();
}
else if(phonecount>10 || phonecount<10)
{
Toast.makeText(FiveActivity.this, "Phone Number Should Contain only 10 Numbers",Toast.LENGTH_LONG).show();
}
else
{
String phoneno="+91"+phonefamfri;
// Toast.makeText(FiveActivity.this, "Good"+phoneno,Toast.LENGTH_LONG).show();
DatabaseHandler3 db = new DatabaseHandler3(this);
//Toast.makeText(FiveActivity.this,name+mailfamfri+phoneno,Toast.LENGTH_LONG).show();
Log.d("Insert: ", "Inserting ..");
Log.d("Insert: ", "Inserting ..");
2014-02-08
Vji
+0
也请您发表调用部分 –