我的应用程序每次都崩溃。每件事在语法上看起来都不错,但不知道错误在哪里?

时间:2018-08-05 05:09:48

标签: android

第二个带有微调框的布局的代码在这里。仅在添加微调器后问题才开始。我将此代码添加到主布局之后的第二个布局中。除了微调框,我还有一个按钮可以切换到下一个第三版面。

package com.example.admin.howdy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 01-Aug-18.
 */

public class second extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        Spinner sp=(Spinner)findViewById(R.id.spinner);
        List<String> categories = new ArrayList<String>();
        categories.add("Automobile");
        categories.add("Business Services");
        categories.add("Computers");
        categories.add("Education");
        categories.add("Personal");
        categories.add("Travel");
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(second.this,android.R.layout.simple_spinner_item,categories);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp.setAdapter(adapter);
        final Button button2 = (Button)findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent myintent2 = new Intent(second.this, third.class);
                startActivity(myintent2);
            }
        });
    }

}
我坚持了很长时间。 活动的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"
    android:background="@drawable/image_2"
    tools:layout_editor_absoluteY="81dp">

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="30dp"
        android:layout_marginStart="13dp"
        android:layout_marginLeft="13dp"
        android:layout_marginTop="37dp"
        android:text="Complete following steps to proceed further."
        android:textAppearance="@style/TextAppearance.AppCompat.Display1"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="18sp"
        app:layout_constraintBottom_toTopOf="@+id/textView3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="14dp"
        android:layout_marginStart="25dp"
        android:layout_marginLeft="25dp"
        android:text="Who are you?"
        android:textSize="16sp"
        app:layout_constraintBottom_toTopOf="@+id/radioGroup"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />

    <RadioGroup
        android:id="@+id/radioGroup"
        android:layout_width="154dp"
        android:layout_height="0dp"
        android:layout_marginBottom="32dp"
        app:layout_constraintBottom_toTopOf="@+id/textView4"
        app:layout_constraintStart_toStartOf="@+id/textView3"
        app:layout_constraintTop_toBottomOf="@+id/textView3">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="7dp"
            android:layout_weight="1"
            android:text="Students"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="16sp" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="4dp"
            android:layout_weight="1"
            android:text="Staffs"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="16sp" />

        <RadioButton
            android:id="@+id/radioButton"
            android:layout_width="wrap_content"
            android:layout_height="7dp"
            android:layout_weight="1"
            android:text="Others"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="16sp" />
    </RadioGroup>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="29dp"
        android:layout_marginBottom="18dp"
        android:layout_marginLeft="24dp"
        android:text="Which instution you belongs to?"
        android:textColor="@color/colorPrimaryDark"
        android:textSize="16sp"
        android:visibility="visible"
        app:layout_constraintBottom_toTopOf="@+id/spinner"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup" />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="249dp"
        android:layout_height="33dp"
        android:layout_marginBottom="49dp"
        android:layout_marginStart="25dp"
        android:layout_marginLeft="25dp"
        android:prompt="@string/app_name"
        android:spinnerMode="dropdown"
        app:layout_constraintBottom_toTopOf="@+id/button2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView4" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="52dp"
        android:layout_marginEnd="28dp"
        android:layout_marginRight="28dp"
        android:background="?android:attr/colorEdgeEffect"
        android:text="Next"
        android:textColor="#FFFFFF"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/spinner"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_editor_absoluteX="137dp" />

</android.support.constraint.ConstraintLayout>
我在logcat中得到这些评论:

08-05 11:42:12.103 4352-4352/? E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system
08-05 11:42:12.103 4352-4352/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
08-05 11:42:12.104 4352-4352/? I/art: Not late-enabling -Xcheck:jni (already on)
08-05 11:42:12.513 4352-4352/com.example.admin.howdy I/InstantRun: starting instant run server: is main process
08-05 11:42:12.772 4352-4352/com.example.admin.howdy W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
08-05 11:42:12.776 4352-4365/com.example.admin.howdy W/art: Suspending all threads took: 5.892ms
08-05 11:42:12.780 4352-4365/com.example.admin.howdy I/art: Background sticky concurrent mark sweep GC freed 2173(224KB) AllocSpace objects, 0(0B) LOS objects, 27% free, 805KB/1117KB, paused 6.924ms total 16.847ms
08-05 11:42:12.871 4352-4365/com.example.admin.howdy W/art: Suspending all threads took: 14.228ms
08-05 11:42:12.878 4352-4365/com.example.admin.howdy I/art: Background partial concurrent mark sweep GC freed 856(231KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 1007KB/2031KB, paused 17.370ms total 60.090ms
08-05 11:42:12.979 4352-4352/com.example.admin.howdy W/ResourceType: Failure getting entry for 0x7f060058 (t=5 e=88) (error -75)
08-05 11:42:12.980 4352-4352/com.example.admin.howdy D/AndroidRuntime: Shutting down VM
08-05 11:42:12.981 4352-4352/com.example.admin.howdy E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.admin.howdy, PID: 4352
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.howdy/com.example.admin.howdy.MainActivity}: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
        at android.view.LayoutInflater.createView(LayoutInflater.java:633)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
        at com.example.admin.howdy.MainActivity.onCreate(MainActivity.java:18)
        at android.app.Activity.performCreate(Activity.java:5990)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5254) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
        at android.view.LayoutInflater.createView(LayoutInflater.java:607)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
        at com.example.admin.howdy.MainActivity.onCreate(MainActivity.java:18) 
        at android.app.Activity.performCreate(Activity.java:5990) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5254) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.admin.howdy:drawable/image_2" (7f060058)  is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060058 a=-1 r=0x7f060058}
        at android.content.res.Resources.loadDrawableForCookie(Resources.java:2441)
        at android.content.res.Resources.loadDrawable(Resources.java:2381)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
        at android.view.View.<init>(View.java:3737)
        at android.view.ViewGroup.<init>(ViewGroup.java:497)
        at android.view.ViewGroup.<init>(ViewGroup.java:493)
        at android.view.ViewGroup.<init>(ViewGroup.java:489)
        at android.support.constraint.ConstraintLayout.<init>(ConstraintLayout.java:566)
        at java.lang.reflect.Constructor.newInstance(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:607) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
        at com.example.admin.howdy.MainActivity.onCreate(MainActivity.java:18) 
        at android.app.Activity.performCreate(Activity.java:5990) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5254) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
08-05 11:42:21.368 4352-4352/? I/Process: Sending signal. PID: 4352 SIG: 9

2 个答案:

答案 0 :(得分:0)

从xml删除此行,然后重试:

android:background="@drawable/image_2"

是大图吗?

答案 1 :(得分:0)

请确保在您或xml fil中添加了正确的约束布局依赖版本,例如

编译'com.android.support.constraint:constraint-layout:1.0.2'