android中的自定义组件问题

android中的自定义组件问题,android,components,Android,Components,我正在尝试在我的Android应用程序中绘制自定义形状。我使用了这个例子,如果我只有这个组件,我可以让它与我的应用程序一起工作。但是,我需要使用自定义形状、2个文本视图和2个按钮。每当我尝试在应用程序中使用按钮和文本视图创建此组件时,应用程序就会失败 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" a

我正在尝试在我的Android应用程序中绘制自定义形状。我使用了这个例子,如果我只有这个组件,我可以让它与我的应用程序一起工作。但是,我需要使用自定义形状、2个文本视图和2个按钮。每当我尝试在应用程序中使用按钮和文本视图创建此组件时,应用程序就会失败

<?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文件,我有点怀疑这就是问题所在。是什么导致了错误

这是行车日志

03-21 19:34:08.810:错误/AndroidRuntime(608):致命异常:主
03-21 19:34:08.810:错误/AndroidRuntime(608):java.lang.RuntimeException:无法启动活动组件信息{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):位于java.lang.reflect.Method.invokenactive(本机方法)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):位于java.lang.reflect.Method.invoke(Method.java:521)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):在dalvik.system.NativeStart.main(本机方法)
03-21 19:34:08.810:错误/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:错误/AndroidRuntime(608):。。。还有11个


我怀疑DemoView会给你带来问题。尝试移除它,然后从那里开始。很抱歉,这不是完整答案。

在应用程序崩溃后粘贴logcat。添加logcat输出,没有它很难猜测,因此您有一个致命的异常。。。由在
ViewData.java
的第77行抛出的
NullPointerException
引起。你能发布你的
onCreate()
方法并告诉我们哪一个是第77行吗?