//hi i am trying to retrieve the data from database and display in my activity.but it is giving error fatal exception main.here when i click showall button all student details shouls get dispalyed.
public class four extends Activity {
Button showall;
MyDataBase mydb;
ListView lv;
int str;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.snd);
mydb=new MyDataBase(four.this);
mydb.openDB();
showall.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Log.i("INFO","ALL DETAILS");
ArrayList<HashMap<String,String>> p2 = mydb.getAllSDetails();
lv = (ListView)findViewById(R.id.listView1);
//coloum.xml contains four text view,and string contains my coloum names.
SimpleAdapter mSchedule = new SimpleAdapter(four.this, p2, R.layout.column,
new String[] {"_Sid","FName", "LName","clss","sec"}, new int[] {R.id.txtfname, R.id.txtlname,R.id.txtage,R.id.txtqual});
lv.setAdapter(mSchedule);
lv.setOnItemClickListener(select);
}
});
}
public OnItemClickListener select=new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
int idd[] = mydb.gettingId();
str = idd[position];
}
};
}
// my error log .i am unable to solve the problem.is there any thing wrong i did in my program. my error log .i am unable to solve the problem.is there any thing wrong i did in my program. can any one please guide me why i am getting the following error.
2-27 08:26:12.098: I/INFO(381): ALL DETAILS
12-27 08:26:12.098: I/INFO(381): database creation
12-27 08:26:12.108: I/INFO(381): Opening database
12-27 08:26:12.148: I/INFO(381): ALL DETAILS
12-27 08:26:12.158: D/AndroidRuntime(381): Shutting down VM
12-27 08:26:12.158: W/dalvikvm(381): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-27 08:26:12.180: E/AndroidRuntime(381): FATAL EXCEPTION: main
12-27 08:26:12.180: E/AndroidRuntime(381): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android/com.android.four}: java.lang.NullPointerException
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.os.Looper.loop(Looper.java:123)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-27 08:26:12.180: E/AndroidRuntime(381): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 08:26:12.180: E/AndroidRuntime(381): at java.lang.reflect.Method.invoke(Method.java:521)
12-27 08:26:12.180: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-27 08:26:12.180: E/AndroidRuntime(381): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-27 08:26:12.180: E/AndroidRuntime(381): at dalvik.system.NativeStart.main(Native Method)
12-27 08:26:12.180: E/AndroidRuntime(381): Caused by: java.lang.NullPointerException
12-27 08:26:12.180: E/AndroidRuntime(381): at com.android.four.onCreate(four.java:40)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-27 08:26:12.180: E/AndroidRuntime(381): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-27 08:26:12.180: E/AndroidRuntime(381): ... 11 more
I think you have not initialized your button “showall“.
Something like
are you missing this?