. - List item
I am doing an application to add and delete the datails of employees to and from database. when i run it ,i am getting the message"unfortunately my app has stopped". pls help me to solve this problem. my logcat shows the following details:
05-21 14:11:45.799: E/AndroidRuntime(527): FATAL EXCEPTION: main
05-21 14:11:45.799: E/AndroidRuntime(527): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aswathy.nicemployee/com.aswathy.nicemployee.NICemployeeActivity}: java.lang.ClassCastException: com.aswathy.nicemployee.NICemployeeActivity cannot be cast to android.view.View$OnClickListener
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.os.Looper.loop(Looper.java:137)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-21 14:11:45.799: E/AndroidRuntime(527): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 14:11:45.799: E/AndroidRuntime(527): at java.lang.reflect.Method.invoke(Method.java:511)
05-21 14:11:45.799: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-21 14:11:45.799: E/AndroidRuntime(527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-21 14:11:45.799: E/AndroidRuntime(527): at dalvik.system.NativeStart.main(Native Method)
05-21 14:11:45.799: E/AndroidRuntime(527): Caused by: java.lang.ClassCastException: com.aswathy.nicemployee.NICemployeeActivity cannot be cast to android.view.View$OnClickListener
05-21 14:11:45.799: E/AndroidRuntime(527): at com.aswathy.nicemployee.NICemployeeActivity.onCreate(NICemployeeActivity.java:31)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.Activity.performCreate(Activity.java:4465)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-21 14:11:45.799: E/AndroidRuntime(527): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-21 14:11:45.799: E/AndroidRuntime(527): ... 11 more
*code of NICemployeeActivity.java is as following:*
package com.aswathy.nicemployee;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class NICemployeeActivity extends Activity implements OnClickListener {
Button sqlUpdate, sqlView;
EditText sqlName, sqlDepartment;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sqlUpdate = (Button) findViewById(R.id.bSQLUpdate);
sqlName = (EditText) findViewById(R.id.etSQLName);
sqlDepartment = (EditText) findViewById(R.id.etSQLDepartment);
sqlView = (Button) findViewById(R.id.bSQLopenView);
sqlView.setOnClickListener(this);
sqlUpdate.setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.bSQLUpdate:
boolean didItWork = true;
try{
String name = sqlName.getText().toString();
String department = sqlDepartment.getText().toString();
DBemployee entry = new DBemployee(NICemployeeActivity.this);
entry.open();
entry.createEntry(name, department);
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("sucess");
d.setContentView(tv);
d.show();
}
}
break;
case R.id.bSQLopenView:
Intent i = new Intent("com.aswathy.nicemployee.NICview");
startActivity(i);
break;
}
}
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}