@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
Rdegtext = (TextView) findViewById(R.id.RdegText);//프래그먼트 1
Ldegtext = (TextView) findViewById(R.id.LdegText);//프래그먼트 1
Rpretext = (TextView) findViewById(R.id.RpreText);//프래그먼트 1
Lpretext = (TextView) findViewById(R.id.LpreText);//프래그먼트 1
TabText= (TextView) findViewById(R.id.TabText);//프래그먼트 2
BluetextView = (TextView) findViewById(R.id.BlueText);//프래그먼트 3
float var0 = event.values[0];
float var1 = event.values[1];
float var2 = event.values[2];
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
TabText.setText(var0+"deg"); //이부분은 잘됩니다.
//Rdegtext.setText("deg"); 이부분만 넣으면 널포인터 익셉션
break;
case Sensor.TYPE_ORIENTATION:
break;
default:
break;
}
}
}
같은 텍스트 뷰이고 똑같이 findViewbyid로 찾고 했는데 다른 textView에 setText를 하면 널포인터익셉션이 납니다... 같은 질문 올렸는데 해결을 못해서 ... 탭 뷰로 구성되어있고 널포인터익셉션 나는 시점이 3번째 탭을 눌렀을 때 입니다.
메인엑티비티 전체코드 주소와 로그캣 첨부합니다.ㅠㅠ
소스는 길어서 링크로 걸겠습니다.
http://blog.naver.com/wit010
로그캣입니다.
01-07 16:25:19.295 14590-14590/? E/SensorManager: Exception dispatching input event.
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: FATAL EXCEPTION: main
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: Process: org.androidtown.Monitoring_1, PID: 14590
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at org.androidtown.actionbar.MainActivity.onSensorChanged(MainActivity.java:167)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at android.hardware.SystemSensorManager$SensorEventQueue.dispatchSensorEvent(SystemSensorManager.java:470)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at android.os.MessageQueue.nativePollOnce(Native Method)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at android.os.MessageQueue.next(MessageQueue.java:143)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:122)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5292)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
01-07 16:25:19.296 14590-14590/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)