null pointer exception at settext
i want to display my table sql in alert dialog using tablerow with inflater
manually make table in score.xml
main.java
//table3
Cursor gethighscorealter=highscoreDB.rawQuery("SELECT*FROM HIGHSCORE3"+
" ORDER BY TIME asc, MOVE asc ;"
, null);
if(gethighscorealter.getCount()>0){
gethighscorealter.moveToFirst();
timer= gethighscorealter.getLong(gethighscorealter.getColumnIndex("TIME"));
move = gethighscorealter.getInt(gethighscorealter.getColumnIndex("MOVE"));
grid = gethighscorealter.getInt(gethighscorealter.getColumnIndex("GRID"));
textView31.setText(""+timer);
textView32.setText(""+move);
textView33.setText(""+grid);
}else{
//textView31.setText("-");textView32.setText("-");textView33.setText("-");
}
score.xml
android:id="@+id/table_score"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*" >android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:selectable="false"
android:focusable="false"
>
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="TIME"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="MOVE"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="GRID"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:selectable="false"
android:focusable="false"
>
android:id="@+id/textView31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:singleLine="true"
android:text="TIME"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
android:id="@+id/textView32"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="MOVE"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
android:id="@+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:text="GRID"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
logcat
06-21 14:05:03.169: E/AndroidRuntime(1504): FATAL EXCEPTION: main
06-21 14:05:03.169: E/AndroidRuntime(1504): java.lang.NullPointerException
06-21 14:05:03.169: E/AndroidRuntime(1504): at skripsi.slidame.PuzzleActivity.highscore(PuzzleActivity.java:280)
06-21 14:05:03.169: E/AndroidRuntime(1504): at skripsi.slidame.PuzzleActivity.onOptionsItemSelected(PuzzleActivity.java:143)
06-21 14:05:03.169: E/AndroidRuntime(1504): at android.app.Activity.onMenuItemSelected(Activity.java:2548)
java:280 should be textView31.setText(""+timer);
when i checked timer with toast i got the value
it think i got nullexception from textview
oncreate method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//db
String DB_PATH= getApplicationContext().getFilesDir().getPath();
highscoreDB = SQLiteDatabase.openDatabase(DB_PATH+slidameBoard.DB_NAME,null,SQLiteDatabase.CREATE_IF_NECESSARY);
new countleft(START_DELAY, INTERVAL);
//sensor
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR_DELAY_NORMAL);
//lebar
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
wm.getDefaultDisplay().getMetrics(displayMetrics);
lebar = displayMetrics.widthPixels;
setContentView(R.layout.activity_slidame4);
textView31 = (TextView)findViewById(R.id.textView31);
textView32 = (TextView)findViewById(R.id.textView32);
textView33 = (TextView)findViewById(R.id.textView33);
textView41 = (TextView)findViewById(R.id.textView41);
textView42 = (TextView)findViewById(R.id.textView42);
textView43 = (TextView)findViewById(R.id.textView43);
}
inflate method
AlertDialog.Builder showhighscore =new AlertDialog.Builder(this);
LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.score, null);//score
showhighscore.setCancelable(false);
showhighscore.setTitle(" ");
showhighscore.setView(layout);
showhighscore.setIcon(R.drawable.menu_icon);
showhighscore.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
onResume();
}
});
showhighscore.show();
.
stackoverflow.comm
Best Moving Company This article sheds light on how we can perceive reality. This one is quite great and has a lot of information. Thank you for the interesting article.
ReplyDelete