###前提・実現したいこと
Androidstudioで加速度センサーの値とテキストファイルの値で演算するプログラムを作っています。ファイルの値は読み込めますが配列へ格納する方法がわかりません。やりたいことは以下の通りです。
テキストファイルを読み込み配列へ格納する。そして加速度センサーで検知された値と演算する。読み込みたいテキストデータは以下のような感じです。
1 5 8
2 6 7
3 9 10
余分なimport文が何個かありますが、お願いいたします。
###発生している問題・エラーメッセージ
str下線部に Valiable ‘str might not have been initialized parseInt下線部に Cannot resolve method
parseInt`(java.lang.String[])
というエラーが出ています。
###該当のソースコード
Java
import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import static com.example.mlab_win.spleadsheet3.R.id.text; import static com.example.mlab_win.spleadsheet3.R.id.textView; class MainActivity extends Activity implements SensorEventListener { private SensorManager mSensorManager; private Sensor mAcceleration; private TextView[] mSensor = new TextView[3]; InputStream is = null; BufferedReader br = null; String text = ""; int Index[][] = new int[325557][]; int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // センサーマネージャの取得 mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mSensor[0] = (TextView) findViewById(R.id.xValue); mSensor[1] = (TextView) findViewById(R.id.a); mSensor[2] = (TextView) findViewById(R.id.zValue); TextView textView =(TextView)findViewById(R.id.a); } @Override protected void onResume() { super.onResume(); // 使用するセンサーの設定 Sensor acceleration = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // センサーを有効にする mSensorManager.registerListener(this, acceleration, SensorManager.SENSOR_DELAY_NORMAL); try { try { // assetsフォルダ内の sample.txt をオープンする is = this.getAssets().open("sample.txt"); br = new BufferedReader(new InputStreamReader(is)); String str; while(str != null){ //strlist.add(str.split(",")); //一行の内容を','で分割してそれぞれを[count=ノード番号]の2次元目の配列の要素として格納 Index[count] = parseInt(str.split(",")); //次の行を読み込み str = br.readLine(); count++; } br.close(); } finally { if (is != null) is.close(); if (br != null) br.close(); } } catch (Exception e){ // エラー発生時の処理 } } @Override protected void onPause() { super.onPause(); // センサーを無効にする if (mSensorManager != null) { mSensorManager.unregisterListener(this); } } @Override public final void onAccuracyChanged(Sensor sensor, int accuracy) { // センサーの精度が変化した場合に呼ばれる } @Override public final void onSensorChanged(SensorEvent event) { // センサーの値が変化した場合に呼ばれる float [] accell= new float[3]; accell[0] = event.values[0]; accell[1] = event.values[1]; accell[2] = event.values[2]; Log.i("加速度", "accell[X] " + accell[0]); Log.i("加速度", "accell[Y] " + accell[1]); Log.i("加速度", "accell[Z] " + accell[2]); } }
###補足情報(言語/FW/ツール等のバージョンなど)
Androidstudio 2.2.3

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/20 09:48