应用程序崩溃:IllegalStateException:RelativeLayout中不存在循环依赖项

时间:2014-01-09 19:15:08

标签: android relativelayout

我正在尝试按照书中的教程。我在一本500页的书上大概有200页,所有内容都运行良好,直到有一天,我收到一条错误消息“不幸的是”应用程序“已停止”。我不想重新开始,并在这个论坛上尝试过解决方案,看看我是否能得到答案,例如转到Windows - 首选项 - 安卓 - DDMS - 滴答ADHOST,重启Eclipse并关闭ADT等,但没有似乎解决了这个问题。 从我收集的内容来看,这个错误对于每个应用程序都是唯一的,我应该在论坛上发布来自logcat的日志,以便比我更聪明的人可以分析它。

以下是logcat的结果:

01-09 18:59:22.559: I/ActivityManager(316): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.androiddevbook.onyourbike.chapter3/.MainActivity} from pid 1896
01-09 18:59:22.591: W/WindowManager(316): Failure taking screenshot for (246x410) to layer 21005
01-09 18:59:22.639: D/AndroidRuntime(1896): Shutting down VM
01-09 18:59:22.669: D/dalvikvm(1896): GC_CONCURRENT freed 96K, 17% free 500K/600K, paused 1ms+4ms, total 22ms
01-09 18:59:22.669: D/jdwp(1896): Got wake-up signal, bailing out of select
01-09 18:59:22.669: D/dalvikvm(1896): Debugger has detached; object registry had 1 entries
01-09 18:59:22.709: D/dalvikvm(1906): Not late-enabling CheckJNI (already on)
01-09 18:59:22.709: I/ActivityManager(316): Start proc com.androiddevbook.onyourbike.chapter3 for activity com.androiddevbook.onyourbike.chapter3/.MainActivity: pid=1906 uid=10051 gids={50051, 1028}
01-09 18:59:23.039: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
01-09 18:59:23.349: E/Trace(1906): error opening trace file: No such file or directory (2)
01-09 18:59:23.779: I/Choreographer(687): Skipped 100 frames!  The application may be doing too much work on its main thread.
01-09 18:59:24.280: D/dalvikvm(1906): GC_FOR_ALLOC freed 67K, 8% free 2500K/2692K, paused 40ms, total 42ms
01-09 18:59:24.299: I/dalvikvm-heap(1906): Grow heap (frag case) to 4.024MB for 1536016-byte allocation
01-09 18:59:24.429: D/dalvikvm(1906): GC_FOR_ALLOC freed 2K, 5% free 3998K/4196K, paused 126ms, total 126ms
01-09 18:59:24.529: D/dalvikvm(1906): GC_CONCURRENT freed <1K, 5% free 3998K/4196K, paused 5ms+25ms, total 91ms
01-09 18:59:24.629: D/dalvikvm(1906): GC_FOR_ALLOC freed <1K, 5% free 3997K/4196K, paused 33ms, total 33ms
01-09 18:59:24.660: I/dalvikvm-heap(1906): Grow heap (frag case) to 7.318MB for 3456016-byte allocation
01-09 18:59:24.739: D/dalvikvm(1906): GC_CONCURRENT freed 0K, 3% free 7372K/7572K, paused 21ms+5ms, total 78ms
01-09 18:59:24.970: D/AndroidRuntime(1906): Shutting down VM
01-09 18:59:24.970: W/dalvikvm(1906): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
**01-09 18:59:24.989: E/AndroidRuntime(1906): FATAL EXCEPTION: main**
01-09 18:59:24.989: E/AndroidRuntime(1906): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1531)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:343)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:363)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.View.measure(View.java:15518)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.View.measure(View.java:15518)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.View.measure(View.java:15518)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.View.measure(View.java:15518)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.Choreographer.doFrame(Choreographer.java:532)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.os.Handler.handleCallback(Handler.java:725)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.os.Looper.loop(Looper.java:137)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at android.app.ActivityThread.main(ActivityThread.java:5041)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at java.lang.reflect.Method.invokeNative(Native Method)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-09 18:59:24.989: E/AndroidRuntime(1906):     at dalvik.system.NativeStart.main(Native Method)
01-09 18:59:24.999: W/ActivityManager(316):   Force finishing activity com.androiddevbook.onyourbike.chapter3/.MainActivity
01-09 18:59:25.009: W/WindowManager(316): Failure taking screenshot for (246x410) to layer 21010
01-09 18:59:25.249: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
01-09 18:59:25.540: W/ActivityManager(316): Activity pause timeout for ActivityRecord{40d01bd0 u0 com.androiddevbook.onyourbike.chapter3/.MainActivity}
01-09 18:59:25.839: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
01-09 18:59:26.089: I/Choreographer(687): Skipped 65 frames!  The application may be doing too much work on its main thread.

有人可以帮我吗?

这是我的AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androiddevbook.onyourbike.chapter3"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="19" />

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

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

        </activity>

            <activity 
                android:name="com.androiddevbook.onyourbike.chapter3.NewPlanet" android:label="@string/activity_title_new_planet"/>

            <activity
                android:name="com.androiddevbook.onyourbike.chapter3.ConfigPlanet" android:label="@string/activity_title_configure_planet"/>

               <activity
                android:name="com.androiddevbook.onyourbike.chapter3.TravelPlanet" android:label="@string/activity_title_travel_planet"/>  

                   <activity
                android:name="com.androiddevbook.onyourbike.chapter3.AttackPlanet" android:label="@string/activity_title_attack_planet"/> 

    </application>

</manifest>

我弄清楚它与哪个xml有关。出现循环依赖性错误的xml数据如下:

<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:background="@drawable/galaxy"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:text="@string/planet_name_label" android:textColor="#FFDDAA" />

    <TextView
        android:id="@+id/textView2"
        android:layout_below="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_mass_label" android:textColor="#FFDDAA"/>

      <TextView
        android:id="@+id/dataView2"
        android:layout_toRightOf="@+id/textView2"
        android:layout_alignStart="@+id/dataView1"
        android:layout_below="@+id/dataView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_mass_label" android:textColor="#FFFF99" />

     <TextView
        android:id="@+id/textView3"
        android:layout_below="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_gravity_label" android:textColor="#FFDDAA"/>

      <TextView
        android:id="@+id/dataView3"
        android:layout_toRightOf="@+id/textView3"
        android:layout_alignStart="@+id/dataView2"
        android:layout_below="@+id/dataView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_gravity_label" android:textColor="#FFFF99"/>

      <TextView
        android:id="@+id/textView4"
        android:layout_below="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_colonies_label" android:textColor="#FFDDAA"/>

      <TextView
        android:id="@+id/dataView4"
        android:layout_toRightOf="@+id/textView4"
        android:layout_alignStart="@+id/dataView3"
        android:layout_below="@+id/dataView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_colonies_label" android:textColor="#FFFF99"/>

       <TextView
        android:id="@+id/textView5"
        android:layout_below="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_population_label" android:textColor="#FFDDAA"/>

        <TextView
        android:id="@+id/dataView5"
        android:layout_toRightOf="@+id/textView5"
        android:layout_alignStart="@+id/dataView4"
        android:layout_below="@+id/dataView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_population_label" android:textColor="#FFFF99"/>

        <TextView
        android:id="@+id/textView6"
        android:layout_below="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_military_label" android:textColor="#FFDDAA"/>

        <TextView
        android:id="@+id/dataView6"
        android:layout_toRightOf="@+id/textView6"
        android:layout_alignStart="@+id/dataView5"
        android:layout_below="@+id/dataView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_military_label" android:textColor="#FFFF99"/>

         <TextView
        android:id="@+id/textView7"
        android:layout_below="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_bases_label" android:textColor="#FFDDAA"/>

        <TextView
        android:id="@+id/dataView7"
        android:layout_toRightOf="@+id/textView7"
        android:layout_alignStart="@+id/dataView6"
        android:layout_below="@+id/dataView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_bases_label" android:textColor="#FFFF99"/>

          <TextView
        android:id="@+id/textView8"
        android:layout_below="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_forcefield_label" android:textColor="#FFDDAA"/>

        <TextView
        android:id="@+id/dataView8"
        android:layout_toRightOf="@+id/textView8"
        android:layout_alignStart="@+id/dataView7"
        android:layout_below="@+id/dataView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/planet_forcefield_label" android:textColor="#FFFF99"/>

<ImageView
    android:id="@+id/imageEarth"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView8"

    android:contentDescription="@string/content_desc_earth"
    android:padding="30dp"
    android:src="@drawable/earth" />

<TextView
    android:id="@+id/dataView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView8"
    android:layout_alignLeft="@+id/dataView7"
    android:text="@string/planet_name_label"
    android:textColor="#FFFF99" />

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

我假设您正在尝试使用两列,即text数据。为了模式,我将dataView1代码移动到textView1下面,并将toRightOf = textView1并取出“alignLeft”和“above”。

<TextView
android:id="@+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/textView1"
android:text="string/planet_name_label"
android:textColor="#FFFF99" />

答案 1 :(得分:0)

我试图找到循环依赖存在的位置....我停下来因为你的代码让我很头疼。也许您可以将TextView1,TextView2,TextView3等以及DataView1,Dataview2,Dataview3等的xml ID名称更改为有意义的内容?