has ended"-6ren"> has ended"-我在 android studio 中构建了一个应用程序,在我的 MainActivity 上,我有一个按钮,单击该按钮会进入另一个 Activity 。然而,当我在实际的外部设备上运行它时,我收到消-6ren">
gpt4 book ai didi

java - 当我在外部设备上运行应用程序时,为什么它给我的是 "unfortunatley has ended"

转载 作者:行者123 更新时间:2023-12-01 17:45:39 24 4
gpt4 key购买 nike

我在 android studio 中构建了一个应用程序,在我的 MainActivity 上,我有一个按钮,单击该按钮会进入另一个 Activity 。然而,当我在实际的外部设备上运行它时,我收到消息说它不幸停止了。然而,在虚拟设备上,它运行得很好。有谁知道发生了什么事吗?

这是我的主要 Activity 代码

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"),错误消息具体说明了

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)

因此,由于您的应用在一台设备上运行良好,但在另一台设备上崩溃,看来您没有为每种设备类型提供可绘制资源。

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

有关此主题的更多信息可以在 Providing Resources 指南中找到

关于java - 当我在外部设备上运行应用程序时,为什么它给我的是 "unfortunatley <app name > has ended",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60871566/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com