1
這是我的情況:我想顯示一些片段。在我的情況下,我有一個學生的SQLite數據庫,字段是: _id,姓名,姓氏,性別,photoSize,field1,field2,field3,field4。例如,如果field1 == 1我必須顯示片段1,如果field2 == 2我必須顯示片段2等等。我不知道我做錯了什麼。這是代碼。FragmentPagerAdapter方法,getItem()錯誤
public class SectionsPagerAdapter extends FragmentPagerAdapter {
Bundle b = getIntent().getExtras();
int i = 2;
Cursor c;
Cursor c2;
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
String id = b.getString("id");
c2 = dbm.buscarAlumno(id);
if (c.moveToFirst()) {
switch (position) {
case 0:
if (c2.getString(5).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 1:
if (c2.getString(6).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 2:
if (c2.getString(7).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 3:
if (c2.getString(8).equals("1")) {
return PlaceholderFragment.newInstance(position);
} else {
break;
}
case 4:
return PlaceholderFragment.newInstance(position);
}
}
return null;
}
@Override
public int getCount() {
// Show 1 total pages.
return 5;
}
@Override
public CharSequence getPageTitle(int position) {
String id = b.getString("id");
c = dbm.buscarAlumno(id);
if (c.moveToFirst()) {
switch (position) {
case 0:
if (c.getString(5).equals("1")){
return "PISTA";
}
case 1:
if (c.getString(6).equals("1")){
return "ESTABLO";
}else{break;}
case 2:
if (c.getString(7).equals("1")){
return "EMOCIONES";
}else{break;}
case 3:
if (c.getString(8).equals("1")){
return "NECESIDADES";
}else{break;}
case 4:
return b.getString("alumno");
}
}return null;
}
}
dBm的變量是在容器類中聲明,指的DatabaseManager和buscarAlumno(ID)是返回的學生,併發誓,這種方法可以完美的方法。這裏是logcat:
12-30 07:43:14.419 3104-3104/? W/EGL_emulation: eglSurfaceAttrib not implemented
12-30 07:43:14.429 3104-3104/? D/OpenGLRenderer: Enabling debug mode 0
12-30 07:43:17.849 1340-1354/? W/Binder: Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException
at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
12-30 07:43:17.849 1253-1353/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 3076 uid 10057
如果我不使用數據庫完美的作品。
請幫忙!謝謝你們!
粘貼'IInputMethodWrapper.java'行的來源:280 –
你有沒有更多的stacktrace - 這只是一個android崩潰,不是特定於你的代碼 – Blundell