Невозможно начать основную деятельность - PullRequest
0 голосов
/ 13 апреля 2020

Вот мой файл приложения. Подскажите, пожалуйста, из-за чего мое приложение взломало sh и что можно сделать, чтобы это исправить?

https://drive.google.com/open?id=1kBmPCesA-hsu44lB2ugnBF-T_2-_JZbE

Вот какая вкладка запуска показывает, logcat не показывает ошибок. Похоже, ошибка возникает при запуске метода onCreate, но я попытался добавить точку останова перед этим методом. Даже тогда приложение вылетает.

Вот 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)
    }
}

Вот строки. 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>

И размеры. 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>

Вот код xml

<?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)

1 Ответ

1 голос
/ 13 апреля 2020

Я скачал ваш проект.

В ваших журналах написано:

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

Итак, ошибка с вашей кнопкой.

Точно, ошибка - это атрибут shadowRadius, потому что вы используете измерения 20dp, но документация Android гласит:

May be a floating point value, such as "1.2".

Если вы измените размеры 20 дп на 20, вы сможете скомпилировать свой код.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...