0

. - 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

}

}

GAYATHRI
  • 11
  • 1
  • 3

4 Answers4

4

Look here

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)

Now open your NICemployeeActivity.java file, and check line 31. You are casting an object of type NICemployeeActivity to View, but you can't.

Nanne
  • 64,065
  • 16
  • 119
  • 163
  • this is not answer it should be comment – Samir Mangroliya May 21 '12 at 09:11
  • 3
    I disagree. With this information you can easily fix the problem. There is not much more you can do here. We could find some trivialities, but that really doesn't matter. If you think there is something wrong, you might want to close the question as too localised or duplicate of the others that have this problem, but this is the origin of the problem. – Nanne May 21 '12 at 09:12
  • thanks for ur comments.but still i cant figure out my problem. i have added the code also. now pls help me to solve this problem. – GAYATHRI May 22 '12 at 06:29
  • Your code is a mess, what are all those `>` doing there? Do you even want us to help you? Please put some effort in asking your question! Did you see where I said "check line 31"? You could've mentioned what line is that line, etc – Nanne May 22 '12 at 06:34
  • are you sure that is the line of the code you are running? That would be strange.... – Nanne May 22 '12 at 08:51
  • line 31 is" switch (arg0.getId()) { ". one more thing , i am getting an error message at setOnClickListener(this) – GAYATHRI May 22 '12 at 08:54
1

try importing with

android.view.View.OnClickListener instead of import android.content.DialogInterface;& import android.content.DialogInterface.OnClickListener;

May above imports might have problem.

Desu
  • 464
  • 4
  • 6
0

You have to change the RAM size, and then restart your emulator.

Then it will work successfully.

Spudley
  • 166,037
  • 39
  • 233
  • 307
-1

You need to add activity to manifest.xml file while you are creating new activity.

Sandy
  • 985
  • 5
  • 13