Here is my app file. Can you please tell what is causing my app to crash and what can be done to fix this?
https://drive.google.com/open?id=1kBmPCesA-hsu44lB2ugnBF-T_2-_JZbE
Here is what the run tab shows, the logcat shows no errors. It seems like the error occurs initiating the onCreate method but i tried adding a breakpoint before that method. Even then the app crashes.
Here is the MainActivity.kt
package com.example.aboutme
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.aboutme.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setContentView(R.layout.activity_main)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
// findViewById<Button>(R.id.submit_button).setOnClickListener {
// showName(it)
// }
binding.doneButton.setOnClickListener {
addNickname(it)
}
}
private fun addNickname(view:View){
binding.apply {
nicknameText.text = nicknameEdit.text
invalidateAll()
nicknameEdit.visibility = View.GONE
doneButton.visibility = View.GONE
nicknameText.visibility = View.VISIBLE
}
//Hide the keyboard.
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
Here is the strings.xml
<resources>
<string name="app_name">AboutMe</string>
<string name="name">Waleed</string>
<string name="yellow_star">Yellow Star</string>
<string name="bio">Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n\n
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \n
Mattis nunc sed blandit libero. Quis vel eros donec ac. Tellus cras\n
adipiscing enim eu turpis egestas. Dui id ornare arcu odio. Venenatis\n
tellus in metus vulputate eu scelerisque felis imperdiet proin. Nulla \n
facilisi nullam vehicula ipsum a arcu cursus. Malesuada fames ac turpis \n
egestas maecenas. Amet commodo nulla facilisi nullam vehicula ipsum a. \n
In mollis nunc sed id semper risus in hendrerit gravida.
\n\n Mtellus in metus vulputate eu scelerisque felis imperdiet proin. Nulla \n
facilisi nullam vehicula ipsum a arcu cursus. Malesuada fames ac turpis \n
egestas maecenas. Amet commodo nulla facilisi nullam vehicula ipsum a. \n
In mollis nunc sed id semper risus in hendrerit gravida..</string>
<string name="hint">Enter your name here</string>
<string name="Submit">Done</string>
</resources>
And the dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="text_size">20sp</dimen>
<dimen name="small_padding">8dp</dimen>
<dimen name="layout_padding">20dp</dimen>
<item name="line_spacing" type="dimen" format="float">1.2</item>
</resources>
Here is the xml code
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingStart="@dimen/layout_padding"
android:paddingEnd="@dimen/layout_padding">
<TextView
android:id="@+id/name_text"
style="@style/name_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/layout_padding"
android:text="@string/name"
android:textAlignment="center" />
<EditText
android:id="@+id/nickname_edit"
style="@style/name_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints=""
android:ems="10"
android:hint="@string/hint"
android:inputType="textPersonName"
android:textAlignment="center" />
<Button
android:id="@+id/done_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#8BC34A"
android:shadowRadius="@dimen/layout_padding"
android:text="@string/Submit"
android:textAlignment="center" />
<TextView
android:id="@+id/nickname_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible" />
<ImageView
android:id="@+id/star_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small_padding"
android:contentDescription="@string/yellow_star"
android:paddingTop="@dimen/layout_padding"
app:srcCompat="@android:drawable/btn_star_big_on" />
<ScrollView
android:id="@+id/bio_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/bio_text"
style="@style/name_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/line_spacing"
android:text="@string/bio" />
</ScrollView>
</LinearLayout>
</layout>
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.aboutme, PID: 11533
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aboutme/com.example.aboutme.MainActivity}: android.view.InflateException: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3333)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
Caused by: android.view.InflateException: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Error inflating class Button
Caused by: android.view.InflateException: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Error inflating class Button
Caused by: java.lang.NumberFormatException: For input string: "20.0dip"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at android.content.res.TypedArray.getFloat(TypedArray.java:475)
at android.widget.TextView.readTextAppearance(TextView.java:4036)
at android.widget.TextView.<init>(TextView.java:1076)
at android.widget.Button.<init>(Button.java:166)
at android.widget.Button.<init>(Button.java:141)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:72)
at androidx.appcompat.widget.AppCompatButton.<init>(AppCompatButton.java:68)
at androidx.appcompat.app.AppCompatViewInflater.createButton(AppCompatViewInflater.java:192)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:111)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:303)
at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
at com.example.aboutme.MainActivity.onCreate(MainActivity.kt:22)
at android.app.Activity.performCreate(Activity.java:7990)
at android.app.Activity.performCreate(Activity.java:7979)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3308)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3477)
E/AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2043)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7464)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:955)
I downloaded your project.
In your logs says:
InflateException: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Binary XML file line #33 in com.example.aboutme:layout/activity_main: Error inflating class Button
So the error is with your Button.
Exactly, the error is the attribute shadowRadius because you are using the 20dp dimens, but the Android documentation says that:
May be a floating point value, such as "1.2".
If you change the 20dp dimens by 20 then you can compile your code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.