2012-12-30 30 views
1

我正在使用Android的Achartengine,并且我有一个由LinearLayout中的ScrollView母亲组成的布局。它包含一个LinearLayout,它是Graph和一些textview e edittext。ScrollView和Achartengine的位置和崩溃

问题是,如果我在LinearLayout的顶部插入图形,然后程序运行,但是如果我在底部插入图形后,所有textview和edittext比程序崩溃。 为什么?

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <!-- android:layout_weight="1" --> 

     <LinearLayout 
      android:id="@+id/chart" 
      android:layout_width="fill_parent" 
      android:layout_height="200dp" 
      android:layout_margin="2dp" 
      android:orientation="horizontal" /> 

     <TextView 
      android:id="@+id/txtX" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="X: 0" 
      android:textSize="15sp" > 
     </TextView> 

     <TextView 
      android:id="@+id/txtZ" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="39dp" 
      android:text="Z: 0" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/txtY" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="35dp" 
      android:text="Y: 0" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/txtM" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="35dp" 
      android:text="M: 0" 
      android:textSize="15sp" /> 

     <TextView 
      android:id="@+id/txtM2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="35dp" 
      android:text="M: 0" 
      android:textSize="15sp" /> 

     <EditText 
      android:id="@+id/et1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="39dp" 
      android:ems="10" 
      android:focusable="false" 
      android:inputType="textMultiLine" > 
     </EditText> 
    </LinearLayout> 

</ScrollView> 

感谢的! :)

PS:这是当logcat中应用程序崩溃:

12-31 13:56:26.839: I/ActivityManager(169): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.spettro1/.MainActivity } from pid 2688 
12-31 13:56:26.849: I/Launcher(2252): onPause() 
12-31 13:56:26.859: D/AndroidRuntime(2688): Shutting down VM 
12-31 13:56:26.889: I/AndroidRuntime(2688): NOTE: attach of thread 'Binder Thread #3' failed 
12-31 13:56:26.899: I/ActivityManager(169): Start proc com.spettro1 for activity com.spettro1/.MainActivity: pid=2697 uid=10125 gids={} 
12-31 13:56:26.969: I/OrientationDebug(169): [pwm] in updateOrientationListenerLp() 
12-31 13:56:26.969: V/OrientationDebug(169): in updateOrientationListenerLp(), Screen status=true, current orientation=-1, SensorEnabled=true 
12-31 13:56:26.969: I/OrientationDebug(169): [pwm] needSensorRunningLp(), return true #4 
12-31 13:56:26.979: I/Launcher(2252): onWindowFocusChanged(false) 
12-31 13:56:26.989: D/Launcher(2252): setWallpaperDimension() called 
12-31 13:56:26.989: D/Launcher(2252): USE_NON_SCROLLABLE_IMAGE_WALLPAPER is true 
12-31 13:56:27.019: D/Launcher(2252): It's image wallpaper. suggestDesiredDimensions(-1,-1) 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 1 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 2 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 3 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 4 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 5 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 6 
12-31 13:56:27.039: D/SensorManager(2697): ====>>>>>Num Sensor: 0 
12-31 13:56:27.039: E/SensorManager(2697): registerListener :: handle = 1600940398 name= Linear Acceleration Sensor delay= 10000 Listener= [email protected] 
12-31 13:56:27.049: E/SensorManager(2697): =======>>>Sensor Thread RUNNING <<<======== 
12-31 13:56:27.049: E/SensorHAL(169): +__poll_activate: handle=0 enabled=1 
12-31 13:56:27.119: D/AndroidRuntime(2697): Shutting down VM 
12-31 13:56:27.119: W/dalvikvm(2697): threadid=1: thread exiting with uncaught exception (group=0x40018578) 
12-31 13:56:27.139: E/AndroidRuntime(2697): FATAL EXCEPTION: main 
12-31 13:56:27.139: E/AndroidRuntime(2697): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.spettro1/com.spettro1.MainActivity}: java.lang.ClassCastException: android.widget.LinearLayout 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.os.Looper.loop(Looper.java:130) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.ActivityThread.main(ActivityThread.java:3687) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at java.lang.reflect.Method.invoke(Method.java:507) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at dalvik.system.NativeStart.main(Native Method) 
12-31 13:56:27.139: E/AndroidRuntime(2697): Caused by: java.lang.ClassCastException: android.widget.LinearLayout 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at com.spettro1.MainActivity.initComponents(MainActivity.java:112) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at com.spettro1.MainActivity.onCreate(MainActivity.java:94) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) 
12-31 13:56:27.139: E/AndroidRuntime(2697):  ... 11 more 
12-31 13:56:27.139: W/ActivityManager(169): Force finishing activity com.spettro1/.MainActivity 
12-31 13:56:27.149: E/(169): Dumpstate > /data/log/dumpstate_app_error 
12-31 13:56:27.649: W/ActivityManager(169): Activity pause timeout for HistoryRecord{4082f818 com.spettro1/.MainActivity} 

这是崩溃代码周围112线,内部的initComponents():

 txtX = (TextView) findViewById(R.id.txtX); 
     txtY = (TextView) findViewById(R.id.txtY); 
     txtZ = (TextView) findViewById(R.id.txtZ); 
     txtM = (TextView) findViewById(R.id.txtM); 
     txtM2 = (TextView) findViewById(R.id.txtM2); 
112  ed1 = (EditText) findViewById(R.id.et1); 

     for(int i=0; i<camp.length; ++i) 
      camp[i]=0; 

NB:TextView的和的EditText的定义是全球(在主要活动之上)和私人,事实上他们在图表位于顶部时运行。

EDIT1:我试图改变第一的LinearLayout在XML到TableLayout,然后我确认这不是问题的第一道的LinearLayout,但也许其中一个实现了图形的LinearLaoyut:

LinearLayout layout = (LinearLayout) findViewById(R.id.chart); 
mChartView = ChartFactory.getBarChartView(getBaseContext(), dataset, multiRenderer, BarChart.Type.DEFAULT); 
layout.addView(mChartView); 

这是从编译器标记错误的initComponents()中调用。 我试图在textview声明之前插入此声明和实例,唯一的变化是logcat不标记任何指定的错误,只是在ActivityThread.performLaunchActivity(ActivityThread $ ActivityClientRecord,Intent)行上崩溃:1651.

+1

发布崩溃的代码:围绕'initComponents'行112,logcat说你正在调用一个视图,它不一定是。当你这样做时,也可以在这里发布w /'@ mango'来通知我。 – mango

+0

我添加了崩溃的代码! 谢谢大家! :) @mango – Gabrer

+0

我不确定我标记的是正确的..是吗? @mango – Gabrer

回答

1

我解决我的问题,增加一个ID为的LinearLayout父:

android:id="@+id/general" 

我不知道为什么它的工作原理,让我感觉不好,因为我担心它是否会在今后的工作中。 也许线性布局之间有冲突。 如果有人了解解决方案可以写在这里。

感谢您的帮助! @mango