2011-03-21 70 views
0

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

<?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:错误/ AndroidRuntime(608):at android.app.ActivityThread .performLaunchActivity(ActivityThread.java:2663)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-21 19:34 :08.810:错误/ AndroidRuntime(60 8):at android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):at android.app.ActivityThread $ H.handleMessage(ActivityThread。 java:2033)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):at android.os.Looper.loop(Looper.java:123)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):at 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/AndroidRu ntime(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):at android.project.realtimedata.ViewData.onCreate(ViewData.java:77)
03-21 19:34:08.810: ERRO R/AndroidRuntime(608):at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):at android.app.ActivityThread.performLaunchActivity(ActivityThread的.java:2627)
03-21 19:34:08.810:ERROR/AndroidRuntime(608):11 ...更多

+0

在应用程序崩溃后粘贴logcat。 – Cristian 2011-03-21 18:51:20

+0

添加logcat输出,很难猜测没有 – Franco 2011-03-21 19:07:22

+0

,所以你有一个致命的例外...由'ViewData.java'的第77行抛出'NullPointerException'引起。你可以发布你的'onCreate()'方法并告诉我们哪一行是第77行? – bigstones 2011-03-21 20:34:04

回答

0

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