GAYATHRI
GAYATHRI

Reputation: 11

unfortunately my app has stopped in android emulator?

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

}

}

Upvotes: 0

Views: 4474

Answers (4)

Desu
Desu

Reputation: 464

try importing with

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

May above imports might have problem.

Upvotes: 1

user2310863
user2310863

Reputation: 1

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

Then it will work successfully.

Upvotes: 0

Sandy
Sandy

Reputation: 1005

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

Upvotes: -1

Nanne
Nanne

Reputation: 64399

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.

Upvotes: 4

Related Questions