Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:59:14+00:00 2026-06-08T13:59:14+00:00

I am using an Activity with a Theme.Dialog to do my AlertDialog as i’m

  • 0

I am using an Activity with a Theme.Dialog to do my AlertDialog as i’m trying to use this dialog inside a BroadcastReceiver but when i added a OnClickListener the application crashes everytime it launches.

Code:

package nyp.android.project;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PasswordDialog extends Activity {

    private static final String TAG = "Logging Activity";
    //Context context;   
    Button login;
    EditText inputPassword;

    private static final int MY_PASSWORD_DIALOG_ID = 0;

    protected void onCreate(Bundle savedInstanceState) 
    {
        //this.context = context;
        super.onCreate(savedInstanceState);
        setContentView (R.layout.password_dialog);

        //SharedPreferences passwdfile = context.getSharedPreferences(    
        //        PhoneFinder.PASSWORD_PREF_KEY, 0); 

        //String correctSHA1 = passwdfile.getString(PhoneFinder.PASSWORD_PREF_KEY, null);

        login = (Button) findViewById(R.id.loginPassword);
        inputPassword = (EditText) findViewById(R.id.btnLogin);

        login.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
              Toast.makeText(PasswordDialog.this, "Hello World!", Toast.LENGTH_LONG).show();
            }
        });
        }

    }

Logcat:

07-25 12:27:30.354: D/AndroidRuntime(570): Shutting down VM
07-25 12:27:30.354: W/dalvikvm(570): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-25 12:27:30.364: E/AndroidRuntime(570): FATAL EXCEPTION: main
07-25 12:27:30.364: E/AndroidRuntime(570): java.lang.RuntimeException: Unable to start activity ComponentInfo{nyp.android.project/nyp.android.project.PasswordDialog}: java.lang.ClassCastException: android.widget.EditText
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.os.Looper.loop(Looper.java:123)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 12:27:30.364: E/AndroidRuntime(570):  at java.lang.reflect.Method.invokeNative(Native Method)
07-25 12:27:30.364: E/AndroidRuntime(570):  at java.lang.reflect.Method.invoke(Method.java:521)
07-25 12:27:30.364: E/AndroidRuntime(570):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 12:27:30.364: E/AndroidRuntime(570):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 12:27:30.364: E/AndroidRuntime(570):  at dalvik.system.NativeStart.main(Native Method)
07-25 12:27:30.364: E/AndroidRuntime(570): Caused by: java.lang.ClassCastException: android.widget.EditText
07-25 12:27:30.364: E/AndroidRuntime(570):  at nyp.android.project.PasswordDialog.onCreate(PasswordDialog.java:38)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-25 12:27:30.364: E/AndroidRuntime(570):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-25 12:27:30.364: E/AndroidRuntime(570):  ... 11 more

XML:

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="10dip" >


        <!--  Password Label -->
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dip"
            android:text="Password" />
        <!--  Password TextField -->

        <EditText
            android:id="@+id/loginPassword"
            android:layout_width="260dp"
            android:layout_height="wrap_content"
            android:password="true" />

        <!--  Login Button -->        
        <Button
            android:id="@+id/btnLogin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dip"
            android:text="Login" />

    </LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:59:16+00:00Added an answer on June 8, 2026 at 1:59 pm
    java.lang.ClassCastException: android.widget.EditText
    

    see above line of error,You are try to refrences EditText ,not Button…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some Activity I'm using @Theme/Dialog, but this appears like old UI 2.3. If
I am trying to emulate a software keyboard using an Activity with Theme.Dialog. The
I have an activity that appears as a dialog using the following custom theme:
I am using an activity with the dialog theme set, and I want it
I am using Theme.Dialog activity to display user a reminder whenever Alarm triggers, It
I'm using an activity with android:theme=@android:style/Theme.Dialog to make it act as a dialog. What
I've got this dialog (I'm simplifying my use case): class EditShoppingListDialog extends AlertDialog {
Is there other way to create an Activity inside an Activity without using Dialog
I started an activity with dialog theme from onReceive() method by using context variable.
I've been trying to using an AlertDialog to open when the user does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.