Почему это дает мне "неудачу" закончилась ", когда я запускаю приложение на внешнем устройстве - PullRequest
0 голосов
/ 26 марта 2020

я создаю приложение в android студии, и на моей MainActivity у меня есть кнопка, которая при нажатии приводит к другой активности. Однако, когда я запустил его на реальном внешнем устройстве, я получил сообщение о том, что оно, к сожалению, остановлено. Однако на виртуальном устройстве он работает отлично. Кто-нибудь знает, что происходит?

Это мой основной код активности

public class MainActivity extends AppCompatActivity {

    TextView greeting;
    Button click;
    Button slope;

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

        //when the surprise button is clicked
        greeting = (TextView) findViewById(R.id.tVGreeting);
        click = (Button) findViewById(R.id.btnClick);
        click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                greeting.setVisibility(View.VISIBLE); //make the result visible
            }
        });
        //when the slope formula button is clicked
        slope = (Button) findViewById(R.id.slopeBtn);
        slope.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goToMathGraphical(); //go to the slope Activity
            }
        });
    }

    //button goes to new activity.
    private void goToMathGraphical()
    {
        Intent intent = new Intent(MainActivity.this, ScrollMathGraph.class);
        startActivity(intent);
    }

Это файл MainActivity XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tV"
        android:layout_width="wrap_content"
        android:layout_height="105dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="Welcome to the  Fornula App!"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.439"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.183" />

    <Button
        android:id="@+id/btnClick"
        android:layout_width="112dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="SUPRISE"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.455"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tV"
        app:layout_constraintVertical_bias="0.728" />

    <TextView
        android:id="@+id/tVGreeting"
        android:layout_width="224dp"
        android:layout_height="83dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="Good Morning"
        android:textSize="20sp"
        android:visibility="invisible"
        app:layout_constraintBottom_toTopOf="@+id/btnClick"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.44"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/tV"
        app:layout_constraintVertical_bias="0.525" />

    <Button
        android:id="@+id/slopeBtn"
        android:layout_width="204dp"
        android:layout_height="68dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:text="GRAPHICAL FORMULAS"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.46"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/btnClick"
        app:layout_constraintVertical_bias="0.293" />

</android.support.constraint.ConstraintLayout>

Это класс ScrollMathGraph

package com.example.formulaapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class ScrollMathGraph extends AppCompatActivity {
    Button slope2d;
    Button distance2d;

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

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Let us Know If we are missing any Formulas", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                Intent i = new Intent(Intent.ACTION_SEND);
                i.setType("message/rfc822");
                i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"xxxx@yahoo.com" , "xxx@gmail.com"});
                i.putExtra(Intent.EXTRA_SUBJECT, "New Formula not in App");
                i.putExtra(Intent.EXTRA_TEXT   , "Hello! please let us know what formula we are missing! Thank you!");
                try {
                    startActivity(Intent.createChooser(i, "Send mail..."));
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(ScrollMathGraph.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
                }
            }
        });

        slope2d = (Button) findViewById(R.id.Slope2D);
        slope2d.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goToSlopeActivity(); //go to the slope Activity
            }
        });
        distance2d = (Button) findViewById(R.id.Distance2D);
        distance2d.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goToDistance2DActivity(); //go to the slope Activity
            }
        });
    }

    //button goes to new activity.
    private void goToSlopeActivity()
    {
        Intent intent = new Intent(ScrollMathGraph.this, SlopeFormula.class);
        startActivity(intent);
    }

    //button goes to new activity.
    private void goToDistance2DActivity()
    {
        Intent intent = new Intent(ScrollMathGraph.this, Distance2D.class);
        startActivity(intent);
    }


}

Это ScrollMathGraph XML файл

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".ScrollMathGraph">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="@drawable/formulas"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

                    </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.22"
        app:srcCompat="@android:drawable/ic_dialog_email" />

    <ScrollView
        android:layout_width="409dp"
        android:layout_height="535dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">


            <TextView
                android:id="@+id/tv2DTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text=" 2D Graphical Formulas "
                android:textSize="25sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/Slope2D"
                android:layout_width="112dp"
                android:layout_height="wrap_content"
                android:text="2D Slope"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="214dp" />

            <Button
                android:id="@+id/Distance2D"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2D Distance"
                tools:layout_editor_absoluteX="15dp"
                tools:layout_editor_absoluteY="303dp" />

            <Button
                android:id="@+id/Midpoint2D"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2D Midpoint" />


            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text=" 3D Graphical Formulas"
                android:textSize="25sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/Slope3D"
                android:layout_width="108dp"
                android:layout_height="wrap_content"
                android:text="3D Slope" />

            <Button
                android:id="@+id/Distance3D"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="3D Distance" />

            <Button
                android:id="@+id/Midpoint3D"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="3D Midpoint" />


        </LinearLayout>
    </ScrollView>

</android.support.constraint.ConstraintLayout>

Это ошибка, которую я получаю

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.formulaapp, PID: 9888
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.formulaapp/com.example.formulaapp.ScrollMathGraph}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.AppBarLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
        at android.app.ActivityThread.access$800(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        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:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.AppBarLayout
        at android.view.LayoutInflater.createView(LayoutInflater.java:663)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:739)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:798)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:520)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:425)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:381)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.example.formulaapp.ScrollMathGraph.onCreate(ScrollMathGraph.java:19)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
        at android.app.ActivityThread.access$800(ActivityThread.java:135) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5017) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.constructNative(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at android.view.LayoutInflater.createView(LayoutInflater.java:637)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:739) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:798) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:520) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:425) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:381) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at com.example.formulaapp.ScrollMathGraph.onCreate(ScrollMathGraph.java:19) 
        at android.app.Activity.performCreate(Activity.java:5231) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
        at android.app.ActivityThread.access$800(ActivityThread.java:135) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5017) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method) 
     Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070063 a=-1 r=0x7f070063}
        at android.content.res.Resources.loadDrawable(Resources.java:2068)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
        at android.view.View.<init>(View.java:3554)
        at android.view.ViewGroup.<init>(ViewGroup.java:470)
        at android.widget.LinearLayout.<init>(LinearLayout.java:176)
        at android.widget.LinearLayout.<init>(LinearLayout.java:172)
        at android.support.design.widget.AppBarLayout.<init>(AppBarLayout.java:173)
        at java.lang.reflect.Constructor.constructNative(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:637) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:739) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:798) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:520) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:425) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:381) 
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at com.example.formulaapp.ScrollMathGraph.onCreate(ScrollMathGraph.java:19) 
        at android.app.Activity.performCreate(Activity.java:5231) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
        at android.app.ActivityThread.access$800(ActivityThread.java:135) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:136) 
        at android.app.ActivityThread.main(ActivityThread.java:5017) 
        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:785) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
        at dalvik.system.NativeStart.main(Native Method) 

Я видел, что эта ошибка относится к одному из классов, которые я написал

 at com.example.formulaapp.ScrollMathGraph.onCreate(ScrollMathGraph.java:19) 

Кто-нибудь знает, что происходит?

1 Ответ

0 голосов
/ 26 марта 2020

AppBarLayout имеет фоновое рисование (android:background="@drawable/formulas"), и в сообщении об ошибке указывается конкретно

Причина: android .content.res.Resources $ NotFoundException: ресурс не является Drawable (цвет или путь): TypedValue {t = 0x1 / d = 0x7f070063 a = -1 r = 0x7f070063} в android .content.res.Resources.loadDrawable (Resources. java: 2068)

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

Не зная больше о ваших папках с нарисованными ресурсами, я могу Предлагаю только убедиться, что у вас есть версия formulas для каждого созвездия.

Более подробную информацию по этой теме c можно найти в руководстве по Предоставление ресурсов

...