android中的自定义组件问题

时间:2011-03-21 18:45:28

标签: android components

我正在尝试在Android应用程序中绘制自定义形状。我使用了这个http://bestsiteinthemultiverse.com/2008/11/android-graphics-example/示例,我可以使用我的应用程序,如果我唯一拥有的是这个组件。但是,我需要使用自定义形状和2个TextViews和2个按钮。每当我尝试使用Buttons和TextViews在我的应用程序中创建此组件时,App就会失败。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="horizontal"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            <Button android:id="@+id/back" android:layout_width="160sp"
                android:textSize="20sp" android:layout_height="wrap_content"
                android:text="Previous" />
            <Button android:id="@+id/next" android:layout_width="160sp"
                android:textSize="20sp" android:layout_height="wrap_content"
                android:text="Next" />
        </LinearLayout>
        <TextSwitcher android:id="@+id/titles"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
        <TextSwitcher android:id="@+id/data"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
        <com.android.example.DemoView android:id="@+id/demoView"
            android:layout_width="fill_parent" android:layout_height="wrap_content" />
        <Button android:id="@+id/info" android:layout_width="fill_parent"
            android:textSize="20sp" android:layout_height="wrap_content"
            android:text="About this App" />
    </LinearLayout>
</ScrollView>

这就是我的布局XML文件,我有点怀疑这是问题所在。可能导致错误的原因是什么?

这是LogCar错误日志。

  

03-21 19:34:08.810:ERROR / AndroidRuntime(608):致命异性:主要
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):java.lang.RuntimeException:无法启动活动ComponentInfo {android.project.realtimedata / android.project.realtimedata.ViewData}:java.lang.NullPointerException
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.os.Handler.dispatchMessage(Handler.java:99)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.os.Looper.loop(Looper.java:123)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.ActivityThread.main(ActivityThread.java:4627)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):at java.lang.reflect.Method.invokeNative(Native Method)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):at java.lang.reflect.Method.invoke(Method.java:521)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):at dalvik.system.NativeStart.main(Native Method)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):引起:java.lang.NullPointerException
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.project.realtimedata.ViewData.onCreate(ViewData.java:77)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  03-21 19:34:08.810:ERROR / AndroidRuntime(608):... 11更多

1 个答案:

答案 0 :(得分:0)

我怀疑DemoView会给你带来问题。尝试删除它并从那里去。对不起,这不是一个完整的答案。