Приложение отключается на android studio, когда я нажимаю кнопку go для другой активности? - PullRequest
0 голосов
/ 26 апреля 2020

Я проверил все, я уверен, что мой код верен на стороне действий, но я не могу понять ошибку, я пытался проверить AndroidManifest. xml, но я не вижу проблемы. Я получаю эту ошибку при выходе из эмулятора:

 *

> V/FA: onActivityCreated D/AndroidRuntime: Shutting down VM
> E/AndroidRuntime: FATAL EXCEPTION: main
>     Process: com.example.dictionnary, PID: 7465
>     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dictionnary/com.example.dictionnary.PlannerActivity}:
> android.view.InflateException: Binary XML file line #72 in
> com.example.dictionnary:layout/activity_planner: Binary XML file line
> #72 in com.example.dictionnary:layout/activity_planner: Error inflating class android.support.widget.RecyclerView
>         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
>         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
>         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:2016)
>         at android.os.Handler.dispatchMessage(Handler.java:107)
>         at android.os.Looper.loop(Looper.java:214)
>         at android.app.ActivityThread.main(ActivityThread.java:7356)
>         at java.lang.reflect.Method.invoke(Native Method)
>         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
>         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
>      Caused by: android.view.InflateException: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner:
> Error inflating class android.support.widget.RecyclerView
>      Caused by: android.view.InflateException: Binary XML file line #72 in com.example.dictionnary:layout/activity_planner: Error inflating class android.support.widget.RecyclerView
>      Caused by: java.lang.ClassNotFoundException: android.support.widget.RecyclerView
>         at java.lang.Class.classForName(Native Method)
>         at java.lang.Class.forName(Class.java:454)
>         at android.view.LayoutInflater.createView(LayoutInflater.java:815)
>         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
>         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
>         at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
>         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
>         at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
>         at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
>         at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
>         at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
>         at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
>         at com.example.dictionnary.PlannerActivity.onCreate(PlannerActivity.java:36)
>         at android.app.Activity.performCreate(Activity.java:7802)
>         at android.app.Activity.performCreate(Activity.java:7791)
>         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
>         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
>         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
>         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:2016)
>         at android.os.Handler.dispatchMessage(Handler.java:107)
>         at android.os.Looper.loop(Looper.java:214)
>         at android.app.ActivityThread.main(ActivityThread.java:7356)
>         at java.lang.reflect.Method.invoke(Native Method)
>         at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
>         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
> E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't
> find class "android.support.widget.RecyclerView" on path:
> DexPathList[[zip file
> "/data/app/com.example.dictionnary-NMLUdW6Y7szWNvSxehbDwQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dictionnary-NMLUdW6Y7szWNvSxehbDwQ==/lib/x86,
> /system/lib, /system/product/lib]]
>         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
>           ... 28 more

*

Вот мой простой MainActivity

       public class MainActivity extends AppCompatActivity {
        private Button searchButton, plannerButton;

        @Override
        public void onCreate(@Nullable Bundle savedInstanceState ) {
            super.onCreate (savedInstanceState);
            setContentView (R.layout.activity_main);

            searchButton = (Button) findViewById (R.id.main_search);
            plannerButton = (Button) findViewById (R.id.main_planner);
            searchButton.setOnClickListener (new View.OnClickListener () {
                @Override
                public void onClick(View v) {
                    openActivity2();

                }
            });
        }
        public void openActivity2(){
            Intent intent = new Intent (this, PlannerActivity.class);
            startActivity(intent);

        }
    }

    And here my activity_main.xml:

        <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        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"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/welcome"
        tools:context=".MainActivity">

        <ImageView
            android:id="@+id/app_logo"
            android:layout_width="300dp"
            android:layout_height="100dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="60dp"
            android:src="@drawable/applogo"
            />

        <TextView
            android:id="@+id/app_slogan"
            android:layout_width="220dp"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="88dp"
            android:layout_marginTop="140dp"
            android:text="Discover Apiales"
            android:textAlignment="center"
            android:textColor="@color/colorPrimary"
            android:textSize="22dp"
            android:textStyle="bold|italic"
            />
        <Button
            android:id="@+id/main_planner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentStart="true"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/buttons"

            android:padding="20dp"
            android:textAllCaps="false"
            android:textSize="10sp"
            android:text="Planner"
            android:textColor="@android:color/white"

            />
        <Button
            android:id="@+id/main_search"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/main_planner"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/input_design"

            android:padding="20dp"
            android:textAllCaps="false"
            android:textSize="10sp"
            android:text="Recherche "
            android:textColor="@android:color/white"

            />




    </RelativeLayout>


and here is the second Activity I want to go to once I click on search button, then I'll do the same with planner button to go to an other activity

        public class PlannerActivity extends AppCompatActivity {

        TextView titlepage, subtitlepage, endpage;
        Button btnAddNew;

        DatabaseReference reference;
        RecyclerView ourdoes;
        ArrayList<MyDoes> list;
        DoesAdapter doesAdapter;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_planner);

            titlepage = findViewById(R.id.titlepage);
            subtitlepage = findViewById(R.id.subtitlepage);
            endpage = findViewById(R.id.endpage);

            btnAddNew = findViewById(R.id.btnAddNew);

            // import font
            Typeface MLight = Typeface.createFromAsset(getAssets(), "fonts/ML.ttf");
            Typeface MMedium = Typeface.createFromAsset(getAssets(), "fonts/MM.ttf");

            // customize font
            titlepage.setTypeface(MMedium);
            subtitlepage.setTypeface(MLight);
            endpage.setTypeface(MLight);

            btnAddNew.setTypeface(MLight);

            btnAddNew.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent a = new Intent(PlannerActivity.this,NewTaskAct.class);
                    startActivity(a);
                }
            });


            // working with data
            ourdoes = findViewById(R.id.ourdoes);
            ourdoes.setLayoutManager(new LinearLayoutManager (this));
            list = new ArrayList<MyDoes>();

            // get data from firebase
            reference = FirebaseDatabase.getInstance().getReference().child("DoesApp");
            reference.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    // set code to retrive data and replace layout
                    for(DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
                    {
                        MyDoes p = dataSnapshot1.getValue(MyDoes.class);
                        list.add(p);
                    }
                    doesAdapter = new DoesAdapter(PlannerActivity.this, list);
                    ourdoes.setAdapter(doesAdapter);
                    doesAdapter.notifyDataSetChanged();
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    // set code to show an error
                    Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_SHORT).show();
                }
            });

        }
    }


Here is my activity_planner.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        android:orientation="vertical"
        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"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#F4F4F4"
        tools:context=".MainActivity">


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:background="@color/colorPrimaryDark"
            android:layout_height="198dp">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_marginLeft="16dp"
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <TextView
                        android:id="@+id/titlepage"
                        android:layout_marginTop="20dp"
                        android:textSize="32sp"
                        android:textColor="#FFF"
                        android:text="My Does"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:id="@+id/subtitlepage"
                        android:textSize="18sp"
                        android:textColor="#4A4E6A"
                        android:layout_marginTop="8dp"
                        android:text="Finish Them Quickly Today"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content" />

                </LinearLayout>

                <Button
                    android:layout_marginTop="35dp"
                    android:layout_marginLeft="60dp"
                    android:id="@+id/btnAddNew"
                    android:text="+"
                    android:background="@drawable/bgbtnnew"
                    android:textSize="38sp"
                    android:textColor="#FFF"
                    android:textAlignment="center"
                    android:layout_width="52dp"
                    android:layout_height="52dp" />

            </LinearLayout>

            <View
                android:layout_marginTop="20dp"
                android:layout_width="match_parent"
                android:background="#131E69"
                android:layout_height="1dp" />

        </LinearLayout>

        <android.support.widget.RecyclerView
            android:id="@+id/ourdoes"
            android:layout_width="match_parent"
            android:layout_marginTop="-60dp"
            android:layout_marginRight="16dp"
            android:layout_marginLeft="16dp"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/endpage"
            android:textSize="16sp"
            android:textColor="#9A9A9A"
            android:layout_marginTop="20dp"
            android:text="No More Does"
            android:textAlignment="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />


    </LinearLayout>



error when the app crashes and quit to go back to the menu of the emulator

V / FA: подключение к удаленному сервису V / FA: действие приостановлено, время: 1117469 D / AndroidRuntime: завершение работы VM E / AndroidRuntime: FATAL EXCEPTION: main Процесс: com.example.dictionnary, PID: 11242 java .lang.RuntimeException: Невозможно запустить действие ComponentInfo {com. example.dictionnary / com.example.dictionnary.PlannerActivity}: java .lang.RuntimeException: ресурс шрифта не найден fonts / ML.ttf в android .app.ActivityThread.performLaunchActivity (ActivityThread. java: 3270) в android .app.ActivityThread.handleLaunchActivity (ActivityThread. java: 3409) в android .app.servertransaction.LaunchActivityItem.execute (LaunchActivityItem. java: 83) в android .app.servertransaction.TransactionExecutor. executeCallbacks (TransactionExecutor. java: 135) в android .app.servertransaction.TransactionExecutor.execute (TransactionExecutor. java: 95) в android .app.ActivityThread $ H.handleMessage ( ActivityThread. java: 2016) в android .os.Handler.dispatchMessage (Обработчик. java: 107) в android .os.Looper.l oop (Looper. java: 214) в android .app.ActivityThread.main (ActivityThread. java: 7356) в java .lang.reflect.Method.invoke (собственный метод) в com. android .internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit. java: 492) в com. android .internal.os.ZygoteInit.main (ZygoteInit. java: 930) Причина: java .lang.RuntimeException: шрифт не найден, шрифты / ML .ttf в android .graphics.Typeface.createFromAsset (гарнитура. java: 965) в com.example.dictionnary.PlannerActivity.onCreate (PlannerActivity. java: 45) в android .app.Activity.performCreate (Activity. java: 7802) в android .app.Activity.performCreate (Activity. java: 7791) в android .app.Instrumentation.callActivityOnCreate (Инструментарий. java: 1299) в android .app.ActivityThread.performLaunchActivity (ActivityThread. java: 3245) в android .app.ActivityThread.handleLaunchActivity (ActivityThread. java: 3409) в android .app.servertransacti on.LaunchActivityItem.execute (LaunchActivityItem. java: 83) в android .app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor. java: 135) в android .app.servertransaction.TransactionExecutor.execute (TransactionExecutor. java: 95) в android .app.ActivityThread $ H.handleMessage (ActivityThread. java: 2016) в android .os.Handler.dispatchMessage (Обработчик. java: 107) в android .os.Looper.l oop (Looper. java: 214) в android .app.ActivityThread.main (ActivityThread. java: 7356) в java .lang.reflect.Method.invoke ( Собственный метод) в com. android .internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit. java: 492) в com. android .internal.os.ZygoteInit.main (ZygoteInit. java: 930 ) I / Process: отправка сигнала. PID: 11242 SIG: 9

Ответы [ 2 ]

0 голосов
/ 28 апреля 2020

Вы используете более старую версию Recyclerview, возможно, не полностью мигрировавшую в AndroidX, просто замените

android.support.widget.RecyclerView

на это в вашем xml

androidx.recyclerview.widget.RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="vertical"
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F4F4F4"
    tools:context=".MainActivity">


    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:background="@color/colorPrimaryDark"
        android:layout_height="198dp">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_marginLeft="16dp"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/titlepage"
                    android:layout_marginTop="20dp"
                    android:textSize="32sp"
                    android:textColor="#FFF"
                    android:text="My Does"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/subtitlepage"
                    android:textSize="18sp"
                    android:textColor="#4A4E6A"
                    android:layout_marginTop="8dp"
                    android:text="Finish Them Quickly Today"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <Button
                android:layout_marginTop="35dp"
                android:layout_marginLeft="60dp"
                android:id="@+id/btnAddNew"
                android:text="+"
                android:background="@drawable/bgbtnnew"
                android:textSize="38sp"
                android:textColor="#FFF"
                android:textAlignment="center"
                android:layout_width="52dp"
                android:layout_height="52dp" />

        </LinearLayout>

        <View
            android:layout_marginTop="20dp"
            android:layout_width="match_parent"
            android:background="#131E69"
            android:layout_height="1dp" />

    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/ourdoes"
        android:layout_width="match_parent"
        android:layout_marginTop="-60dp"
        android:layout_marginRight="16dp"
        android:layout_marginLeft="16dp"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/endpage"
        android:textSize="16sp"
        android:textColor="#9A9A9A"
        android:layout_marginTop="20dp"
        android:text="No More Does"
        android:textAlignment="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>
0 голосов
/ 26 апреля 2020

Можете ли вы проверить свой файл activity_planner. xml. Проверьте номер строки 72
android .support.widget.RecyclerView.

...