为什么当我在外部设备上运行应用程序时会给我一个"unfortunatley <app name > has ended"



im在android studio中构建一个应用程序,在我的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) 

有人知道发生了什么事吗?

AppBarLayout有一个后台可绘制(android:background="@drawable/formulas"(,错误消息特别显示

原因:android.content.res.Resources$NotFoundException:资源不是可绘制的(颜色或路径(:TypedValue{t=0x1/d=0x7f070063 a=-1 r=0x7f070063}在android.content.res.Resources.loadDrawable(Resources.java:2068(

因此,由于您的应用程序在一台设备上运行良好,在另一台设备中崩溃,因此您似乎没有为每种设备类型提供可提取的资源。

在不了解更多关于可绘制资源文件夹的信息的情况下,我只能建议您确保每个星座都有一个formulas可绘制版本。

关于这个主题的更多信息可以在提供资源指南中找到

最新更新