运行应用程序时,应用程序崩溃。我不知道为什么?

时间:2018-11-04 16:59:18

标签: android android-studio error-handling

当我尝试将其加载到我的应用程序时,我的应用程序特定页面崩溃。 有人可以找到错误。 我将发布代码的xml和java文件以及错误。

Java代码:

    package com.divesh.sliderapp;

import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class Team extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.team,container,false);

        TextView txt = view.findViewById(R.id.Name1);
        Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "Fonts/KoHo-Bold.ttf");
        txt.setTypeface(font);
        Typeface font2 = Typeface.createFromAsset(getActivity().getAssets(), "Fonts/KoHo-Regular.ttf");
        TextView txt1 = view.findViewById(R.id.Name2);
        TextView txt2 = view.findViewById(R.id.Pos1);
        TextView txt3 = view.findViewById(R.id.Pos2);
        txt1.setTypeface(font);
        txt2.setTypeface(font2);
        txt3.setTypeface(font2);
        TextView join = view.findViewById(R.id.join);
        Typeface font1 = Typeface.createFromAsset(getActivity().getAssets(), "Fonts/Raleway-Medium.ttf");
        join.setTypeface(font1);
        return view;

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //you can set the title for your toolbar here for different fragments different titles
        getActivity().setTitle("Team");
    }
}

这是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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f2dede">

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="114dp"
        android:layout_height="94dp"
        android:layout_marginBottom="12dp"
        android:layout_marginEnd="135dp"
        android:layout_marginStart="135dp"
        android:layout_marginTop="40dp"
        app:layout_constraintBottom_toTopOf="@+id/Name1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.481"
        app:srcCompat="@drawable/image2"
        android:gravity="center"
        android:contentDescription="@string/divesh_jain" />

    <TextView
        android:id="@+id/Name1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="115dp"
        android:layout_marginStart="116dp"
        android:text="@string/divesh_jain"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textSize="25sp"
        app:layout_constraintBottom_toTopOf="@+id/Pos1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginRight="115dp"
        android:layout_marginLeft="116dp"
        android:gravity="center"/>

    <TextView
        android:id="@+id/Pos1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="32dp"
        android:layout_marginEnd="157dp"
        android:layout_marginStart="158dp"
        android:text="@string/developer"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textSize="16sp"
        app:layout_constraintBottom_toTopOf="@+id/imageView8"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginRight="157dp"
        android:layout_marginLeft="158dp"
        android:gravity="center"/>

    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="114dp"
        android:layout_height="94dp"
        android:layout_marginBottom="12dp"
        android:layout_marginEnd="135dp"
        android:layout_marginStart="135dp"
        app:layout_constraintBottom_toTopOf="@+id/Name2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/image5"
        android:gravity="center"
        android:contentDescription="@string/aman_jain" />

    <TextView
        android:id="@+id/Name2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="132dp"
        android:layout_marginStart="133dp"
        android:text="@string/aman_jain"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textSize="25sp"
        app:layout_constraintBottom_toTopOf="@+id/Pos2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginRight="132dp"
        android:layout_marginLeft="133dp"
        android:gravity="center"/>

    <TextView
        android:id="@+id/Pos2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="100dp"
        android:layout_marginEnd="161dp"
        android:layout_marginStart="162dp"
        android:text="@string/designer"
        android:textAppearance="@style/TextAppearance.AppCompat"
        android:textSize="16sp"
        app:layout_constraintBottom_toTopOf="@+id/join"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginRight="161dp"
        android:layout_marginLeft="162dp"
        android:gravity="center"/>

    <TextView
        android:id="@+id/join"
        android:layout_width="190dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_marginEnd="32dp"
        android:layout_marginStart="33dp"
        android:text="@string/wish_to_join_our_team_contact_us_via_query_section"
        android:textAlignment="center"
        android:textAppearance="@style/TextAppearance.AppCompat"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginRight="32dp"
        android:layout_marginLeft="33dp"
        android:gravity="center"/>
</android.support.constraint.ConstraintLayout>

我将粘贴在logcat中显示的错误,但我认为这些错误均不适用于此页面 该页面名称是团队

这是logcat中显示的错误。

  

11-04 19:19:57.875 5921-5921 / com.divesh.sliderapp E / AndroidRuntime:FATAL EXCEPTION:main       流程:com.divesh.sliderapp,PID:5921       java.lang.RuntimeException:无法启动活动ComponentInfo {com.divesh.sliderapp / com.divesh.sliderapp.payment}:android.view.InflateException:二进制XML文件行#64:错误膨胀了类android.widget.ImageButton           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)           在android.app.ActivityThread.access $ 800(ActivityThread.java:151)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:135)           在android.app.ActivityThread.main(ActivityThread.java:5254)           在java.lang.reflect.Method.invoke(本机方法)           在java.lang.reflect.Method.invoke(Method.java:372)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)        原因:android.view.InflateException:二进制XML文件行#64:错误膨胀了类android.widget.ImageButton           在android.view.LayoutInflater.createView(LayoutInflater.java:633)           在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)           在android.view.LayoutInflater.inflate(LayoutInflater.java:504)           在android.view.LayoutInflater.inflate(LayoutInflater.java:414)           在android.view.LayoutInflater.inflate(LayoutInflater.java:365)           在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)           在android.app.Activity.setContentView(Activity.java:2145)           在com.divesh.sliderapp.payment.onCreate(payment.java:53)           在android.app.Activity.performCreate(Activity.java:5990)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)           在android.app.ActivityThread.access $ 800(ActivityThread.java:151)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:135)           在android.app.ActivityThread.main(ActivityThread.java:5254)           在java.lang.reflect.Method.invoke(本机方法)           在java.lang.reflect.Method.invoke(Method.java:372)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)        造成原因:java.lang.reflect.InvocationTargetException           在java.lang.reflect.Constructor.newInstance(本地方法)           在java.lang.reflect.Constructor.newInstance(Constructor.java:288)           在android.view.LayoutInflater.createView(LayoutInflater.java:607)           在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)           在android.view.LayoutInflater.inflate(LayoutInflater.java:504)           在android.view.LayoutInflater.inflate(LayoutInflater.java:414)           在android.view.LayoutInflater.inflate(LayoutInflater.java:365)           在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)           在android.app.Activity.setContentView(Activity.java:2145)           在com.divesh.sliderapp.payment.onCreate(payment.java:53)           在android.app.Activity.performCreate(Activity.java:5990)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)           在android.app.ActivityThread.access $ 800(ActivityThread.java:151)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:135)           在android.app.ActivityThread.main(ActivityThread.java:5254)           在java.lang.reflect.Method.invoke(本机方法)           在java.lang.reflect.Method.invoke(Method.java:372)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)        造成原因:android.content.res.Resources $ NotFoundException:资源“ com.divesh.sliderapp:drawable / card10”(7f08005e)不是Drawable(颜色或路径):TypedValue {t = 0x1 / d = 0x7f08005e a =- 1 r = 0x7f08005e}           在android.content.res.Resources.loadDrawableForCookie(Resources.java:2441)           在android.content.res.Resources.loadDrawable(Resources.java:2381)           在android.content.res.TypedArray.getDrawable(TypedArray.java:749)           在android.widget.ImageView(ImageView.java:146)           在android.widget.ImageButton。(ImageButton.java:86)           在android.widget.ImageButton。(ImageButton.java:82)           在android.widget.ImageButton。(ImageButton.java:78)           在java.lang.reflect.Constructor.newInstance(本地方法)           在java.lang.reflect.Constructor.newInstance(Constructor.java:288)           在android.view.LayoutInflater.createView(LayoutInflater.java:607)           在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)           在android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)           在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)           在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)           在android.view.LayoutInflater.inflate(LayoutInflater.java:504)           在android.view.LayoutInflater.inflate(LayoutInflater.java:414)           在android.view.LayoutInflater.inflate(LayoutInflater.java:365)           在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)           在android.app.Activity.setContentView(Activity.java:2145)           在com.divesh.sliderapp.payment.onCreate(payment.java:53)           在android.app.Activity.performCreate(Activity.java:5990)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)           在android.app.ActivityThread.access $ 800(ActivityThread.java:151)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:135)           在android.app.ActivityThread.main(ActivityThread.java:5254)           在java.lang.reflect.Method.invoke(本机方法)           在java.lang.reflect.Method.invoke(Method.java:372)           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)   11-04 19:20:00.461 5921-5921 /? I / Process:正在发送信号。 PID:5921 SIG:9

4 个答案:

答案 0 :(得分:0)

我认为主要问题是在用“活动”中的容器替换片段时膨胀了

答案 1 :(得分:0)

从错误日志中:

  

android.content.res.Resources $ NotFoundException:资源   “ com.divesh.sliderapp:drawable / card10”(7f08005e)不是Drawable   (颜色或路径)

这意味着您尝试使用可绘制的card10,但这不是可绘制的。
尽管您发布的xml不使用任何可绘制的card10

错误日志还指向xml的第64行,在您发布的xml中我找到了imageView8。在这种情况下,可能已在此属性中设置了一张非常大的图片,可能会导致应用崩溃:

app:srcCompat="@drawable/image5"

答案 2 :(得分:0)

尝试在onViewCreated中使用View.findViewById():)所有对象都可以像View一样访问

View.findViewById(R.id.textview).setText(“ hello world”);

尽管如此:https://usman.sagri.co.in/pdaceapp/app/src/main/java/in/co/sagri/pdace/ContactFragment.java

您可以正确地返回视图并像在我的Java文件中那样移动代码。

答案 3 :(得分:0)

imageView7.setImageResource(R.drawable.image2)

尝试以编程方式设置图像,这将解决错误