Answer the question
In order to leave comments, you need to log in
Crashes when using Cursor in Android for DataBase?
The code is the following:
database = new DataBase(CompaniesActivity.this);
sql = database.getWritableDatabase();
Cursor cursor = sql.query(database.TABLE_COMPANY, new String[]{
database.UID, database.COMPANY_NAME, database.COMPANY_INDUSTRY}, null,
null,
null,
null,
null
);
while (cursor.moveToNext()) {
String name = cursor.getString(cursor
.getColumnIndex(database.COMPANY_NAME));
name_out.setText(name + "");
}
String name = cursor.getString(cursor .getColumnIndex(database.COMPANY_NAME));
06-04 17:07:36.651 16266-16266/plays_app.app_1 W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40a611f8)
06-04 17:07:36.667 16266-16266/plays_app.app_1 E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at plays_app.app_1.CompaniesActivity.dialog_info(CompaniesActivity.java:156)
at plays_app.app_1.CompaniesActivity$1.onItemClick(CompaniesActivity.java:103)
at android.widget.AdapterView.performItemClick(AdapterView.java:292)
at android.widget.AbsListView.performItemClick(AbsListView.java:1067)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2523)
at android.widget.AbsListView$1.run(AbsListView.java:3184)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Answer the question
In order to leave comments, you need to log in
That's what the problem was, you need to do this instead:
Write like this:
since the initialization of the text field happens in the dialog itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question