自定义Android ViewGroup Forcecloses

时间:2012-02-16 10:17:52

标签: android android-layout viewgroup

所以我基本上是在寻找可以侧滚动并锁定到位的自定义ViewGroup,并在此处找到一个:https://github.com/ysamlan/horizontalpager/tree/master/src/com/github/ysamlan/horizontalpager

之后,我继续编辑我的attrs.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="HorizontalPager">
    <attr name="handle" format="reference" />
    <attr name="content" format="reference" />
    <attr name="collapsedHeight" format="dimension" />
</declare-styleable>
</resources>

因此修复了主要xml的问题(或者Eclipse说的):

<?xml version="1.0" encoding="utf-8"?>
<!--main.xml-->
<com.vrise.bellarmine.HorizontalPager      xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:cl="http://schemas.android.com/apk/res/com.vrise.bellarmine"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:id="@+id/real_view_switcher">
<LinearLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffccd0"
>
     <TextView
        android:text="Countries List"
    android:textColor="#b3000d"
    android:gravity="center_vertical|center_horizontal"
    android:textSize="26dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:background="#ffb0b6"
    android:layout_marginBottom="5dip"
    android:typeface="sans"/>
 <RelativeLayout
  android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="#570000">
 <TextView android:id="@+id/tv_1"
    android:textColor="#FFFFFF"
    android:gravity="center_vertical|left"
    android:textSize="16dip"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:typeface="serif"
    android:layout_width="70dip"
    android:paddingLeft="20dip"
    android:text="Abbr">
 </TextView>
 <TextView android:id="@+id/tv_2"
    android:textColor="#FFFFFF"
    android:gravity="center_vertical|left"
    android:textSize="16dip"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:typeface="serif"
    android:layout_width="200dip"
    android:layout_toRightOf="@+id/tv_1"
    android:text="Countries">
 </TextView>

</RelativeLayout>
<ListView
android:id="@+id/lv_country"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:cacheColorHint="#00000000">
</ListView>
 </LinearLayout>
  </com.vrise.bellarmine.HorizontalPager>

然而,错误日志仍然给我eclipse.buildId = M20110909-1335

Error
Thu Feb 16 02:05:50 PST 2012
com.vrise.bellarmine.HorizontalPager failed to instantiate.

java.lang.NullPointerException
at com.vrise.bellarmine.HorizontalPager.init(HorizontalPager.java:131)
at com.vrise.bellarmine.HorizontalPager.<init>(HorizontalPager.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)

这是什么原因?我想我做的所有事情都是正确的......

0 个答案:

没有答案