Answer the question
In order to leave comments, you need to log in
Why do errors pop up and the application crashes?
I wrote a simple application, I don’t understand, I’ve already broken my head, why do errors pop up?
Errors:
Process: mple.myapplication, PID: 21144
java.lang.RuntimeException: Unable to start activity ComponentInfo{mple.myapplication/mple.myapplication.MainActivity}: java.lang.ClassCastException: com.gc.materialdesign.views.ButtonRectangle cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.gc.materialdesign.views.ButtonRectangle cannot be cast to android.widget.Button
at mple.myapplication.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
package mple.myapplication;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity
{
private Button logBtn;
private EditText emailText;
private EditText passText;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
logBtn = (Button)findViewById(R.id.logBtn);
emailText = (EditText)findViewById(R.id.emailText);
passText = (EditText)findViewById(R.id.passText);
logBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (emailText.getText().toString().matches(""))
{
emailText.setError("Email field can't be empty");
}
if (passText.getText().toString().matches(""))
{
passText.setError("Pass field can't be empty");
}
else
{
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this,
R.layout.activity_main);
progressDialog.setIndeterminate(true);
progressDialog.setMessage("Authenticating...");
progressDialog.show();
}
}
});
}
}
Answer the question
In order to leave comments, you need to log in
But here it is written:
And there is even a line number with an error, line 25:
Here is this line:
While in fact it is enough just to know that the problem is in onCreate (), then you can comment on the lines of onCreate () one by one and see if the error disappears.
The problem is that in the XML layout you have a third-party control - com.gc.materialdesign.views.ButtonRectangle
and you want to load it into a variable of the usual Button type, naturally, due to type incompatibility, there is a problem here, since you use ButtonRectangle in the layout, then in Java also use ButtonRectangle, but rather just fix the layout so that it does not have such "troubles" and has regular Buttons, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question