ScrollView and Achartengine position and crash

1

I'm using Achartengine for Android, and i have layout composed by a ScrollView mother within a LinearLayout. It contains a LinearLayout which is the Graph and some textview e edittext.

The problem is that if i insert the graph on the top of LinearLayout then the program run, but if i insert the graph on the bottom, after all the textview and edittext than the program crash. Why?

This is my XML code:

<?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>

Thanks! :)

PS: This is LogCat when the application crashes:

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= com.spettro1.MainActivity@40519c70
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}

This is crashing-code around the 112 line, inside the 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: definition of textview and edittext are global (on the top of mainactivity) and private, infact they run when the graph is on the top.

Edit1: I tried to change the first LinearLayout in the XML to a TableLayout, then I verified that the problems is not the first LinearLayout but maybe the LinearLaoyut where I implements the graph:

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

This is called out of initComponents() where the compilers tag the error. I tried to insert this declaration and instantiation before the textview declaration, the only thing that changed was that the logcat do not tag any specified error, just crash on ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1651.

android
charts
scrollview
achartengine
android-scrollview
asked on Stack Overflow Dec 30, 2012 by Gabrer • edited Jul 14, 2020 by Gabrer

1 Answer

2

I resolve my problem adding an ID to the LinearLayout parent:

android:id="@+id/general"

I don't know why it works, so i feel bad because I'm worry if it will work in future. Maybe there was a conflict between the linearlayout. If someone understand the solution could write here.

Thanks for help me! @mango

answered on Stack Overflow Jan 10, 2013 by Gabrer • edited Jul 14, 2020 by Gabrer

User contributions licensed under CC BY-SA 3.0