Note that there are some explanatory texts on larger screens.

plurals
  1. POAccelerometer Android "Unfortunately, has stopped"
    text
    copied!<p>I'm now learning accelerometer for android, I found some code and try to make an accelerometer, but my apps suddenly stopped with message "Unfortunately, <em>*</em> has stopped" I have checked other Qs about this, but I found nothing helped. I'm really newbie in android coding...</p> <p>Here's my Java Code :</p> <pre><code>package paket.accelerometer_axis; import android.app.Activity; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.widget.TextView; public class accelerometer_axis extends Activity implements SensorEventListener{ private SensorManager sensorManager; TextView xCoor; TextView yCoor; TextView zCoor; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_accelerometer_axis); xCoor=(TextView)findViewById(R.id.xcoor); yCoor=(TextView)findViewById(R.id.ycoor); zCoor=(TextView)findViewById(R.id.zcoor); sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE); sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);} public void onAccuracyChanged(Sensor sensor,int accuracy){ } public void onSensorChanged(SensorEvent event){ if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){ float x=event.values[0]; float y=event.values[1]; float z=event.values[2]; xCoor.setText("X: "+x); yCoor.setText("Y: "+y); zCoor.setText("Z: "+z); }}} </code></pre> <p>Here's my layout :</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/back" android:padding="4dip"&gt; &lt;ImageView android:id="@+id/icon" android:contentDescription="@string/description_logo" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="6dip" android:src="@drawable/ic_launcher" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:gravity="center_vertical" android:text="@string/text0" android:textColor="#00FF00" android:textSize="20sp" /&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" android:singleLine="true" android:ellipsize="marquee" android:text="@string/text1" /&gt; &lt;TextView android:id="@+id/xcoor" android:text="@string/text2" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /&gt; &lt;TextView android:id="@+id/ycoor" android:text="@string/text3" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /&gt; &lt;TextView android:id="@+id/zcoor" android:text="@string/text4" android:layout_width="fill_parent" android:layout_height="0dip" android:layout_weight="1" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Here's my Manifest :</p> <blockquote> <p></p> <pre><code>&lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /&gt; &lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".Accelerometer_axis" android:label="@string/title_activity_accelerometer_axis" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; </code></pre> <p></p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload