I want help in this, I can't find out the problem.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alnassre.prayingobserver"
android:versionCode="2"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
<uses-feature android:name="android.hardware.sensor.light" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.alnassre.prayingobserver.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and
package com.alnassre.prayingobserver;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager m_sensor_manager;
private Sensor m_accelerometer;
final Button button = (Button) findViewById(R.id.btn1);
final TextView txt_rkoa = (TextView) findViewById(R.id.textView1);
final TextView txt_sjod = (TextView) findViewById(R.id.textView2);
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
m_sensor_manager = (SensorManager) getSystemService(SENSOR_SERVICE);
m_accelerometer = m_sensor_manager.getDefaultSensor(Sensor.TYPE_LIGHT);
setContentView(R.layout.activity_main);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int tkoa = Integer.parseInt(txt_rkoa.getText().toString());
tkoa++;
txt_rkoa.setText(String.valueOf(tkoa));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
protected void onResume()
{
super.onResume();
m_sensor_manager.registerListener(this, m_accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
public void onSensorChanged(SensorEvent event)
{
_("onSensorChanged");
_("" + event.values[0]);
// Toast.makeText(this, "onSensorChanged "+ event.values[0], Toast.LENGTH_SHORT).show();
Log.i("onSensorChanged ", event.values[0]+"");
}
public void onAccuracyChanged(Sensor sensor, int accuracy)
{
Toast.makeText(this, "onAccuracyChanged", Toast.LENGTH_SHORT).show();
}
private void _(String msg)
{
Log.d("chovanec", msg);
}
}
Error statement:
05-19 22:13:24.664: E/AndroidRuntime(12565): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.alnassre.prayingobserver/com.alnassre.prayingobserver.MainActivity}: java.lang.NullPointerException