I'm currently developing an Android app and I'm having a problem that ends up making my program crash from the moment I click the "SignIn" button.
The App has no problem at the time it reaches the main activity, but always crashes when the button is pressed.
There is basically some kind of problem with the code that is escaping me and unfortunately Android Studio also ends up giving no clue as to the problem itself besides the log you can see down there.
> 05-12 18:42:57.687 32378-32378/com.cars.evd.dealership
> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.cars.evd.dealership, PID: 32378
> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cars.evd.dealership/com.cars.evd.dealership.main.SignIn}:
> android.view.InflateException: Binary XML file line #53: Binary XML
> file line #53: Error inflating class info.hoang8f.widget.FButton
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
> at android.app.ActivityThread.-wrap11(Unknown Source:0)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
> at android.os.Handler.dispatchMessage(Handler.java:106)
> at android.os.Looper.loop(Looper.java:164)
> at android.app.ActivityThread.main(ActivityThread.java:6494)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
> Caused by: android.view.InflateException: Binary XML file line #53: Binary XML file line #53: Error inflating class info.hoang8f.widget.FButton
> Caused by: android.view.InflateException: Binary XML file line #53: Error inflating class info.hoang8f.widget.FButton
> Caused by: java.lang.reflect.InvocationTargetException
> at java.lang.reflect.Constructor.newInstance0(Native Method)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
> at android.view.LayoutInflater.createView(LayoutInflater.java:647)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
> at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
> at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
> at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
> at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
> at com.cars.evd.dealership.main.SignIn.onCreate(SignIn.java:25)
> at android.app.Activity.performCreate(Activity.java:7009)
> at android.app.Activity.performCreate(Activity.java:7000)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
> at android.app.ActivityThread.-wrap11(Unknown Source:0)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
> at android.os.Handler.dispatchMessage(Handler.java:106)
> at android.os.Looper.loop(Looper.java:164)
> at android.app.ActivityThread.main(ActivityThread.java:6494)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
> Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 1 to color: type=0x5
> at android.content.res.TypedArray.getColor(TypedArray.java:473)
> at info.hoang8f.widget.FButton.parseAttrs(FButton.java:116)
> at info.hoang8f.widget.FButton.<init>(FButton.java:52)
> at java.lang.reflect.Constructor.newInstance0(Native Method)
> at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
> at android.view.LayoutInflater.createView(LayoutInflater.java:647)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
> at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
> at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
> at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
> at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
> at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
> at com.cars.evd.dealership.main.SignIn.onCreate(SignIn.java:25)
> at android.app.Activity.performCreate(Activity.java:7009)
> at android.app.Activity.performCreate(Activity.java:7000)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
> at android.app.ActivityThread.-wrap11(Unknown Source:0)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
> at android.os.Handler.dispatchMessage(Handler.java:106)
> at android.os.Looper.loop(Looper.java:164)
> at android.app.ActivityThread.main(ActivityThread.java:6494)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Manifest
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SignIn"> <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> </activity> </application> </manifest>
MainActivity.Java
Button btnSignIn, btnSignUp; TextView txtSlogan; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnSignIn = (Button) findViewById(R.id.btnSignIn); btnSignUp = (Button) findViewById(R.id.btnSignUp); txtSlogan = (TextView) findViewById(R.id.txtSlogan); Typeface face = Typeface.createFromAsset(getAssets(), "fonts/NABILA.TTF"); txtSlogan.setTypeface(face); btnSignUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent SignUp = new Intent(MainActivity.this, SignUp.class); startActivity(SignUp); } }); btnSignIn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent SignIn = new Intent(MainActivity.this, SignIn.class); startActivity(SignIn); } }); } }
activity_main.xml
<LinearLayout android:orientation="vertical" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/imageView" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/logo" /> <TextView android:id="@+id/txtSlogan" android:layout_width="200dp" android:layout_height="wrap_content" android:gravity="center" android:text="@string/slogan" android:textColor="@android:color/white" /> </LinearLayout> <LinearLayout android:orientation="horizontal" android:layout_alignParentBottom="true" android:weightSum="2" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnSignUp" style="@style/Widget.AppCompat.Button" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="8dp" android:layout_weight="1" android:background="@color/btnSignActive" android:text="@string/SignUp" android:textColor="@android:color/white" /> <Button android:id="@+id/btnSignIn" style="@style/Widget.AppCompat.Button" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="8dp" android:layout_weight="1" android:background="@color/btnSignActive" android:text="@string/SignIn" android:textColor="@android:color/white" /> </LinearLayout>
SignIn.Java
public class SignIn extends AppCompatActivity { EditText edtemail, edtPassword; Button btnSignIn; @Override protected void onCreate(Bundle saveInstanceState) { super.onCreate(saveInstanceState); setContentView(R.layout.activity_sign_in); edtPassword = (MaterialEditText) findViewById(R.id.edtPassword); edtemail = (MaterialEditText) findViewById(R.id.edtemail); btnSignIn = (Button) findViewById(R.id.btnSignIn); //Init Firebase final FirebaseDatabase database = FirebaseDatabase.getInstance(); final DatabaseReference table_user = database.getReference("User"); btnSignIn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final ProgressDialog mDialog = new ProgressDialog(SignIn.this); mDialog.setMessage("Please Wait..."); mDialog.show(); table_user.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { //check if user not exist in database if(dataSnapshot.child(edtemail.getText().toString()).exists()) { //get user information mDialog.dismiss(); User user = dataSnapshot.child(edtemail.getText().toString()).getValue(User.class); assert user != null; user.setName(edtemail.getText().toString()); if (user.getPassword().equals(edtPassword.getText().toString())) { } else { Toast.makeText(SignIn.this, "Wrong Password !", Toast.LENGTH_SHORT).show(); } }else{ Toast.makeText(SignIn.this, "User not exist in Database !", Toast.LENGTH_SHORT).show(); } } @Override public void onCancelled(DatabaseError databaseError) { } }); } }); } }
SignIn.xml
<LinearLayout android:orientation="vertical" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_centerInParent="true" android:layout_width="match_parent" android:layout_height="wrap_content"> <com.rengwuxian.materialedittext.MaterialEditText android:id="@+id/edtemail" android:hint="@string/name_of_e_mail" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColorHint="@android:color/white" android:text="@string/daniel25_gmail_com" android:textColor="@android:color/white" android:textSize="34sp" android:inputType="phone" app:met_baseColor="@android:color/white" app:met_floatingLabel="highlight" app:met_maxCharacters="11" app:met_primaryColor="@android:color/white" app:met_singleLineEllipsis="true" /> <com.rengwuxian.materialedittext.MaterialEditText android:id="@+id/edtPassword" android:hint="@string/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:textColorHint="@android:color/white" android:text="@string/_1234" android:textColor="@android:color/white" android:textSize="34sp" android:inputType="textPassword" app:met_baseColor="@android:color/white" app:met_floatingLabel="highlight" app:met_maxCharacters="11" app:met_primaryColor="@android:color/white" app:met_singleLineEllipsis="true" /> </LinearLayout> <info.hoang8f.widget.FButton android:id="@+id/btnSignIn" android:text="@string/SignIn" android:textColor="@android:color/white" android:layout_marginRight="8dp" android:layout_marginLeft="8dp" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp" app:buttonColor="@color/btnSignActive" app:shadowColor="@android:color/black" app:shadowEnabled="true" app:shadowHeight="5dp" app:cornerRadius="4dp" /> </RelativeLayout>