活动不断崩溃

时间:2016-03-11 03:49:25

标签: java android xml

我用一个Activity创建了一个应用程序但是当我尝试运行它时(我通过USB连接了我的OPT)它一直在崩溃。我希望至少我能看到第一个屏幕,但我觉得我做错了什么。这是我到目前为止所做的:

MainActivity.java -

package com.excalibur.present;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

activity_main.xml中

这就是它的样子 enter image description here

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.excalibur.present">

    <application
        android:allowBackup="true"
        android:icon="@drawable/iot_logo"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/iot_background"
    tools:context="com.excalibur.present.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Hey! Enter your name"
        android:id="@+id/textView"
        android:layout_marginTop="78dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="175dp"
        android:layout_height="50dp"
        android:inputType="textPersonName"
        android:text="name"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="68dp"
        android:background="#FFFFFF"
        android:textColor="#000000"
        android:paddingLeft="65dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Attendance critera?"
        android:id="@+id/textView2"
        android:layout_marginTop="125dp"
        android:textColor="#000000"
        android:layout_below="@+id/editText"
        android:layout_centerHorizontal="true" />

    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar"
        android:layout_below="@+id/textView2"
        android:layout_alignParentStart="true"
        android:layout_marginTop="40dp"
        android:layout_alignEnd="@+id/textView"
        android:max="100"
        android:progress="80"
        android:indeterminate="false" />

    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar2"
        android:layout_marginTop="50dp"
        android:max="100"
        android:progress="100"
        android:indeterminate="false"
        android:layout_below="@+id/seekBar"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@+id/textView3" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Theory"
        android:id="@+id/textView3"
        android:layout_above="@+id/seekBar2"
        android:layout_toEndOf="@+id/textView"
        android:textColor="#000000" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Lab"
        android:id="@+id/textView4"
        android:textColor="#000000"
        android:layout_alignBottom="@+id/seekBar2"
        android:layout_alignEnd="@+id/textView3" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="DONE"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:background="#FF5454" />
</RelativeLayout>

logcat的:

03-12 19:18:14.542 16002-16002/? I/art: Late-enabling -Xcheck:jni
03-12 19:18:15.200 16002-16002/com.excalibur.present I/art: Alloc partial concurrent mark sweep GC freed 161(28KB) AllocSpace objects, 0(0B) LOS objects, 56% free, 800KB/1824KB, paused 644us total 13.821ms
03-12 19:18:15.223 16002-16002/com.excalibur.present I/art: Alloc concurrent mark sweep GC freed 47(13KB) AllocSpace objects, 0(0B) LOS objects, 56% free, 786KB/1810KB, paused 692us total 17.688ms
03-12 19:18:15.223 16002-16002/com.excalibur.present I/art: Forcing collection of SoftReferences for 308MB allocation
03-12 19:18:15.245 16002-16002/com.excalibur.present I/art: Alloc concurrent mark sweep GC freed 9(256B) AllocSpace objects, 0(0B) LOS objects, 56% free, 786KB/1810KB, paused 595us total 21.969ms
03-12 19:18:15.246 16002-16002/com.excalibur.present E/art: Throwing OutOfMemoryError "Failed to allocate a 324000012 byte allocation with 1048480 free bytes and 255MB until OOM"
03-12 19:18:15.257 16002-16002/com.excalibur.present I/art: Alloc partial concurrent mark sweep GC freed 8(288B) AllocSpace objects, 0(0B) LOS objects, 56% free, 786KB/1810KB, paused 741us total 6.744ms
03-12 19:18:15.274 16002-16002/com.excalibur.present I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 56% free, 786KB/1810KB, paused 1.380ms total 16.042ms
03-12 19:18:15.274 16002-16002/com.excalibur.present I/art: Forcing collection of SoftReferences for 308MB allocation
03-12 19:18:15.291 16002-16002/com.excalibur.present I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 56% free, 786KB/1810KB, paused 837us total 16.483ms
03-12 19:18:15.292 16002-16002/com.excalibur.present E/art: Throwing OutOfMemoryError "Failed to allocate a 324000012 byte allocation with 1048576 free bytes and 255MB until OOM"
03-12 19:18:15.292 16002-16002/com.excalibur.present D/skia: --- allocation failed for scaled bitmap
03-12 19:18:15.304 16002-16002/com.excalibur.present D/AndroidRuntime: Shutting down VM
03-12 19:18:15.305 16002-16002/com.excalibur.present E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.excalibur.present, PID: 16002
                                                                       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.excalibur.present/com.excalibur.present.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2354)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416)
                                                                           at android.app.ActivityThread.access$900(ActivityThread.java:154)
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                           at android.os.Looper.loop(Looper.java:135)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5300)
                                                                           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:904)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
                                                                        Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.RelativeLayout
                                                                           at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                                                                           at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
                                                                           at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
                                                                           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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
                                                                           at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
                                                                           at com.excalibur.present.MainActivity.onCreate(MainActivity.java:11)
                                                                           at android.app.Activity.performCreate(Activity.java:6088)
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416) 
                                                                           at android.app.ActivityThread.access$900(ActivityThread.java:154) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5300) 
                                                                           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:904) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
                                                                        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 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
                                                                           at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
                                                                           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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
                                                                           at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
                                                                           at com.excalibur.present.MainActivity.onCreate(MainActivity.java:11) 
                                                                           at android.app.Activity.performCreate(Activity.java:6088) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416) 
                                                                           at android.app.ActivityThread.access$900(ActivityThread.java:154) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5300) 
                                                                           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:904) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
                                                                        Caused by: java.lang.OutOfMemoryError: Failed to allocate a 324000012 byte allocation with 1048576 free bytes and 255MB until OOM
                                                                           at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
                                                                           at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
                                                                           at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:609)
                                                                           at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
                                                                           at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:988)
                                                                           at android.content.res.Resources.loadDrawableForCookie(Resources.java:2497)
                                                                           at android.content.res.Resources.loadDrawable(Resources.java:2404)
                                                                           at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
                                                                           at android.view.View.<init>(View.java:3743)
                                                                           at android.view.ViewGroup.<init>(ViewGroup.java:498)
                                                                           at android.widget.RelativeLayout.<init>(RelativeLayout.java:249)
                                                                           at android.widget.RelativeLayout.<init>(RelativeLayout.java:245)
                                                                           at android.widget.RelativeLayout.<init>(RelativeLayout.java:241)
                                                                           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 com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55) 
                                                                           at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) 
                                                                           at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) 
                                                                           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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
                                                                           at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
                                                                           at com.excalibur.present.MainActivity.onCreate(MainActivity.java:11) 
                                                                           at android.app.Activity.performCreate(Activity.java:6088) 
                                                                           at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
                                                                           at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 
                                                                           at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416) 
                                                                           at android.app.ActivityThread.access$900(ActivityThread.java:154) 
                                                                           at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1322) 
                                                                           at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                           at android.os.Looper.loop(Looper.java:135) 
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5300) 
                                                                           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:904) 
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
03-12 19:18:15.308 16002-16002/com.excalibur.present D/AppTracker: App Event: crash
03-12 19:18:15.683 16002-16002/com.excalibur.present I/Process: Sending signal. PID: 16002 SIG: 9

1 个答案:

答案 0 :(得分:-1)

尝试: AppCompatActivity的布局主题也需要是AppCompat主题。

但请粘贴清单和布局文件。