I am trying to populate a listview using a database that i have saved in my assets. I have gotten as far as checking to see if the database is being created when i run the app(which it is). My current problem is trying to figure out how to get the columns and display them in a list view. My columns are name,position and department, in case you see a piece of code you don't understand. i've been trying to use code from http://saigeethamn.blogspot.com/2011/02/listview-of-data-from-sqlitedatabase.html
if anybody is able to help me, I would be really grateful, Thank You in Advanced.
EDIT: When code runs it gives me a null pointer exception
public class Favorites extends ListActivity {
public static String tableName = "fac";
private ListView lv;
SQLiteDatabase newDB;
private ArrayList<String> results = new ArrayList<String>();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favorites);
openAndQueryDatabase();
displayResultList();
}
private void displayResultList() {
TextView tView = new TextView(this);
tView.setText("This data is retrieved from the database and only 4 "
+ "of the results are displayed");
getListView().addHeaderView(tView);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results));
getListView().setTextFilterEnabled(true);
}
private void openAndQueryDatabase() {
try {
DataBaseHelper dbHelper = new DataBaseHelper(
this.getApplicationContext());
newDB = dbHelper.getWritableDatabase();
Cursor c = newDB.rawQuery("SELECT name, position FROM " + tableName
+ "where ", null);
if (c != null) {
if (c.moveToFirst()) {
do {
String name = c.getString(c.getColumnIndex("name"));
String position = c.getString(c
.getColumnIndex("position"));
results.add("name: " + name + ",Position " + position);
} while (c.moveToNext());
}
}
} catch (SQLiteException se) {
} finally {
if (newDB != null)
{
newDB.execSQL("DELETE FROM " + tableName);
newDB.close();
}}
}
}
LogCat:
04-24 04:43:19.064: E/AndroidRuntime(1644): FATAL EXCEPTION: main
04-24 04:43:19.064: E/AndroidRuntime(1644): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cerealBarApps/com.cerealBarApps.Faculty_tab}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cerealBarApps/com.cerealBarApps.Favorites}: java.lang.NullPointerException
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.access$1500(ActivityThread.java:132)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.os.Looper.loop(Looper.java:143)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.main(ActivityThread.java:4196)
04-24 04:43:19.064: E/AndroidRuntime(1644): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 04:43:19.064: E/AndroidRuntime(1644): at java.lang.reflect.Method.invoke(Method.java:507)
04-24 04:43:19.064: E/AndroidRuntime(1644): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 04:43:19.064: E/AndroidRuntime(1644): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 04:43:19.064: E/AndroidRuntime(1644): at dalvik.system.NativeStart.main(Native Method)
04-24 04:43:19.064: E/AndroidRuntime(1644): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cerealBarApps/com.cerealBarApps.Favorites}: java.lang.NullPointerException
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1651)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:656)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.widget.TabHost.setCurrentTab(TabHost.java:326)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.widget.TabHost.addTab(TabHost.java:216)
04-24 04:43:19.064: E/AndroidRuntime(1644): at com.cerealBarApps.Faculty_tab.onCreate(Faculty_tab.java:55)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
04-24 04:43:19.064: E/AndroidRuntime(1644): ... 11 more
04-24 04:43:19.064: E/AndroidRuntime(1644): Caused by: java.lang.NullPointerException
04-24 04:43:19.064: E/AndroidRuntime(1644): at com.cerealBarApps.Favorites.openAndQueryDatabase(Favorites.java:63)
04-24 04:43:19.064: E/AndroidRuntime(1644): at com.cerealBarApps.Favorites.onCreate(Favorites.java:25)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
04-24 04:43:19.064: E/AndroidRuntime(1644): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
Sorry
Try this plz..
In the below statment, please put ' ' before 'where' keyword.
Old
Cursor c = newDB.rawQuery("SELECT name, position FROM " + tableName + "where ", null);
New
Cursor c = newDB.rawQuery("SELECT name, position FROM " + tableName + " where ", null);
Related
04-24 21:51:06.092: I/global(406): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
04-24 21:51:06.296: D/PlsParser(406): Playlist Url = http:/ / 85 dot 204 dot 233 dot 122/radio-01/stream-high-02/playlist.m3u8?wowzasessionid=1094958256
04-24 21:51:06.296: I/System.out(406): Playlist: Selected url - http:/ / 85 dot 204 dot 233 dot 122/radio-01/stream-high-02/playlist.m3u8?wowzasessionid=1094958256
04-24 21:51:06.616: E/MediaPlayer(406): error (1, -2147483648)
04-24 21:51:06.622: E/MediaPlayer(406): Error (1,-2147483648)
04-24 21:51:06.622: I/System.out(406): RadioService: stop
04-24 21:51:06.632: E/MediaPlayer(406): stop called in state 0
04-24 21:51:06.632: E/MediaPlayer(406): error (-38, 0)
04-24 21:51:06.652: V/ERROR(406): MEDIA ERROR UNKNOWN -2147483648
04-24 21:51:06.672: E/MediaPlayer(406): stop called in state 1
04-24 21:51:06.672: E/MediaPlayer(406): error (-38, 0)
04-24 21:51:06.692: D/PlsParser(406): Setting next stream from playlist: 0
04-24 21:51:06.692: D/PlsParser(406): URL = http:/ / 85 dot 204 dot 233 dot 122/radio-01/stream-high-02/playlist.m3u8?wowzasessionid=1094958256
04-24 21:51:06.822: I/global(406): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
04-24 21:51:07.002: D/PlsParser(406): Playlist Url = http:/ / 85 dot 204 dot 233 dot 122:1935/radio-01/_definst_/stream-high-02/key.m3u8key?wowzasessionid=1094958256"
04-24 21:51:07.002: W/dalvikvm(406): threadid=18: thread exiting with uncaught exception (group=0x4001d800)
04-24 21:51:07.002: E/AndroidRuntime(406): FATAL EXCEPTION: Thread-21
04-24 21:51:07.002: E/AndroidRuntime(406): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
04-24 21:51:07.002: E/AndroidRuntime(406): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
04-24 21:51:07.002: E/AndroidRuntime(406): at java.util.ArrayList.get(ArrayList.java:311)
04-24 21:51:07.002: E/AndroidRuntime(406): at com.my.radio.RadioService$3.run(RadioService.java:294)
04-24 21:51:07.002: E/AndroidRuntime(406): at java.lang.Thread.run(Thread.java:1096)
04-24 21:51:07.432: D/webviewglue(406): nativeDestroy view: 0x3037c0
04-24 21:51:07.442: D/webviewglue(406): nativeDestroy view: 0x303450
04-24 21:51:08.022: D/dalvikvm(406): GC_EXPLICIT freed 5811 objects / 296264 bytes in 501ms
04-24 21:51:08.412: E/ActivityThread(406): Activity com.my.radio.MainActivity has leaked ServiceConnection com.my.radio.BaseActivity$1#45fd26a8 that was originally bound here
04-24 21:51:08.412: E/ActivityThread(406): android.app.ServiceConnectionLeaked: Activity com.my.radio.MainActivity has leaked ServiceConnection com.my.radio.BaseActivity$1#45fd26a8 that was originally bound here
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread$PackageInfo$ServiceDispatcher.<init>(ActivityThread.java:1121)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread$PackageInfo.getServiceDispatcher(ActivityThread.java:1016)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ContextImpl.bindService(ContextImpl.java:863)
04-24 21:51:08.412: E/ActivityThread(406): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
04-24 21:51:08.412: E/ActivityThread(406): at com.my.radio.BaseActivity.onCreate(BaseActivity.java:39)
04-24 21:51:08.412: E/ActivityThread(406): at com.my.radio.MainActivity.onCreate(MainActivity.java:79)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-24 21:51:08.412: E/ActivityThread(406): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 21:51:08.412: E/ActivityThread(406): at android.os.Looper.loop(Looper.java:123)
04-24 21:51:08.412: E/ActivityThread(406): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-24 21:51:08.412: E/ActivityThread(406): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:51:08.412: E/ActivityThread(406): at java.lang.reflect.Method.invoke(Method.java:521)
04-24 21:51:08.412: E/ActivityThread(406): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-24 21:51:08.412: E/ActivityThread(406): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-24 21:51:08.412: E/ActivityThread(406): at dalvik.system.NativeStart.main(Native Method)
04-24 21:51:08.463: E/ActivityThread(406): Activity com.my.radio.MainActivity has leaked ServiceConnection com.my.radio.MainActivity$2#45fd30d8 that was originally bound here
04-24 21:51:08.463: E/ActivityThread(406): android.app.ServiceConnectionLeaked: Activity com.my.radio.MainActivity has leaked ServiceConnection com.my.radio.MainActivity$2#45fd30d8 that was originally bound here
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread$PackageInfo$ServiceDispatcher.<init>(ActivityThread.java:1121)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread$PackageInfo.getServiceDispatcher(ActivityThread.java:1016)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ContextImpl.bindService(ContextImpl.java:863)
04-24 21:51:08.463: E/ActivityThread(406): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
04-24 21:51:08.463: E/ActivityThread(406): at com.my.radio.MainActivity.onCreate(MainActivity.java:85)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-24 21:51:08.463: E/ActivityThread(406): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 21:51:08.463: E/ActivityThread(406): at android.os.Looper.loop(Looper.java:123)
04-24 21:51:08.463: E/ActivityThread(406): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-24 21:51:08.463: E/ActivityThread(406): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:51:08.463: E/ActivityThread(406): at java.lang.reflect.Method.invoke(Method.java:521)
04-24 21:51:08.463: E/ActivityThread(406): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-24 21:51:08.463: E/ActivityThread(406): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-24 21:51:08.463: E/ActivityThread(406): at dalvik.system.NativeStart.main(Native Method)
04-24 21:51:09.452: I/Process(406): Sending signal. PID: 406 SIG: 9
welcome to Stackoverflow.com :), i think you have an IndexOutofBounds Exception: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
this is an example of how i play an .M3U8 using a VideoView:
private VideoView myvideoview;
private String urlStream;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String streamV = "http://media.jorgesys.com/reforma.m3u8";
new playM3U8().execute(streamV);
myvideoview = (VideoView)this.findViewById(R.id.myvideoview);
myvideoview.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
myvideoview.start();
}
});
myvideoview.setOnErrorListener(new OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.i("Exception", "url: " + url);
return false;
}
});
}
This class is an AyncTask to play the M3U8:
class playM3U8 extends AsyncTask<String, Void, Void> {
private Exception exception;
protected Void doInBackground(String... urls) {
urlStream = urls[0];
runOnUiThread(new Runnable() {
#Override
public void run() {
myvideoview.setVideoURI(Uri.parse(urlStream));
}
});
return null;
}
protected void onPostExecute(String feed) {
Log.i("*** Streaming M3U8", "url: " + urlStream );
}
}
I'm experiencing a NullPointerException and ForceClose issue when clicking the back button after launching either the gallery or the default audio player using the android application I've built.
I've seen a few examples that state I'll need to finish the activity or check for a back button press - but I'm not sure how exactly that would fit into this scenario.
It's crashing on line 84 which is: Uri selectedImage = data.getData();
Source:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_VIDEO) {
{
Uri selectedVideo = data.getData();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedVideo, "video/*");
startActivity(intent);
}
} else if (requestCode == SELECT_PHOTO) {
Uri selectedImage = data.getData();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(selectedImage, "image/*");
startActivity(intent);
}
LogCat:
04-24 21:04:26.441: D/AndroidRuntime(4491): Shutting down VM
04-24 21:04:26.441: W/dalvikvm(4491): threadid=1: thread exiting with uncaught exception (group=0x41df5930)
04-24 21:04:26.451: E/AndroidRuntime(4491): FATAL EXCEPTION: main
04-24 21:04:26.451: E/AndroidRuntime(4491): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.tablet.hairmax/com.tablet.hairmax.UI}: java.lang.NullPointerException
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.ActivityThread.access$1100(ActivityThread.java:141)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.os.Looper.loop(Looper.java:137)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.ActivityThread.main(ActivityThread.java:5039)
04-24 21:04:26.451: E/AndroidRuntime(4491): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:04:26.451: E/AndroidRuntime(4491): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 21:04:26.451: E/AndroidRuntime(4491): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-24 21:04:26.451: E/AndroidRuntime(4491): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-24 21:04:26.451: E/AndroidRuntime(4491): at dalvik.system.NativeStart.main(Native Method)
04-24 21:04:26.451: E/AndroidRuntime(4491): Caused by: java.lang.NullPointerException
04-24 21:04:26.451: E/AndroidRuntime(4491): at com.tablet.hairmax.UI.onActivityResult(UI.java:84)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.Activity.dispatchActivityResult(Activity.java:5293)
04-24 21:04:26.451: E/AndroidRuntime(4491): at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
04-24 21:04:26.451: E/AndroidRuntime(4491): ... 11 more
04-24 21:04:28.721: I/Process(4491): Sending signal. PID: 4491 SIG: 9
04-24 21:04:39.681: D/AndroidRuntime(4543): Shutting down VM
04-24 21:04:39.681: W/dalvikvm(4543): threadid=1: thread exiting with uncaught exception (group=0x41df5930)
04-24 21:04:39.691: E/AndroidRuntime(4543): FATAL EXCEPTION: main
04-24 21:04:39.691: E/AndroidRuntime(4543): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=0, data=null} to activity {com.tablet.hairmax/com.tablet.hairmax.UI}: java.lang.NullPointerException
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.ActivityThread.access$1100(ActivityThread.java:141)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.os.Looper.loop(Looper.java:137)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.ActivityThread.main(ActivityThread.java:5039)
04-24 21:04:39.691: E/AndroidRuntime(4543): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:04:39.691: E/AndroidRuntime(4543): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 21:04:39.691: E/AndroidRuntime(4543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-24 21:04:39.691: E/AndroidRuntime(4543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-24 21:04:39.691: E/AndroidRuntime(4543): at dalvik.system.NativeStart.main(Native Method)
04-24 21:04:39.691: E/AndroidRuntime(4543): Caused by: java.lang.NullPointerException
04-24 21:04:39.691: E/AndroidRuntime(4543): at com.tablet.hairmax.UI.onActivityResult(UI.java:76)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.Activity.dispatchActivityResult(Activity.java:5293)
04-24 21:04:39.691: E/AndroidRuntime(4543): at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
04-24 21:04:39.691: E/AndroidRuntime(4543): ... 11 more
04-24 21:05:14.191: D/AndroidRuntime(4586): Shutting down VM
04-24 21:05:14.191: W/dalvikvm(4586): threadid=1: thread exiting with uncaught exception (group=0x41df5930)
04-24 21:05:14.191: E/AndroidRuntime(4586): FATAL EXCEPTION: main
04-24 21:05:14.191: E/AndroidRuntime(4586): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=0, data=null} to activity {com.tablet.hairmax/com.tablet.hairmax.UI}: java.lang.NullPointerException
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.ActivityThread.deliverResults(ActivityThread.java:3319)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3362)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.ActivityThread.access$1100(ActivityThread.java:141)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.os.Looper.loop(Looper.java:137)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.ActivityThread.main(ActivityThread.java:5039)
04-24 21:05:14.191: E/AndroidRuntime(4586): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 21:05:14.191: E/AndroidRuntime(4586): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 21:05:14.191: E/AndroidRuntime(4586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-24 21:05:14.191: E/AndroidRuntime(4586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-24 21:05:14.191: E/AndroidRuntime(4586): at dalvik.system.NativeStart.main(Native Method)
04-24 21:05:14.191: E/AndroidRuntime(4586): Caused by: java.lang.NullPointerException
04-24 21:05:14.191: E/AndroidRuntime(4586): at com.tablet.hairmax.UI.onActivityResult(UI.java:84)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.Activity.dispatchActivityResult(Activity.java:5293)
04-24 21:05:14.191: E/AndroidRuntime(4586): at android.app.ActivityThread.deliverResults(ActivityThread.java:3315)
04-24 21:05:14.191: E/AndroidRuntime(4586): ... 11 more
data is null. You need to check before that line if data is null. Since you are pressing the Back button, you aren't sending an Intent back with setResult() like would normally be done.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if (resultCode == Activity.RESULT_OK) {
if (data != null)
{
if (requestCode == SELECT_VIDEO) {
Uri selectedVideo = data.getData();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedVideo, "video/*");
startActivity(intent);
} else if (requestCode == SELECT_PHOTO) {
Uri selectedImage = data.getData();
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(selectedImage, "image/*");
startActivity(intent);
}
}
See this answer about getting an image from gallery
My SQLite database appears to be entering entries fine however I cannot pull them back to view them, everytime I load the activity my app crashes, Changing the database version throws a SQL exception and force closes the app also.
Below is the class where the SQL is handled:
package com.uhi.fatfighter;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Stats {
public static final String KEY_ROWID = "_id";
public static final String KEY_WEIGHT = "weight";
public static final String KEY_WAIST = "waist";
public static final String KEY_CHEST = "chest";
public static final String KEY_LEGS = "legs";
public static final String KEY_ARMS = "arms";
private static final String DATABASE_NAME = "statsDB";
private static final String DATABASE_TABLE = "personalStats";
private static final int DATABASE_VERSION = 3;
private DbHelper ffHelper;
private final Context ffContext;
private SQLiteDatabase ffDatabase;
private static class DbHelper extends SQLiteOpenHelper {
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_WEIGHT
+ " TEXT NOT NULL, " + KEY_WAIST + " TEXT NOT NULL, "
+ KEY_CHEST + " TEXT NOT NULL, " + KEY_LEGS
+ " TEXT NOT NULL, " + KEY_ARMS + " TEXT NOT NULL);");
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXIST " + DATABASE_TABLE);
onCreate(db);
}
}
public Stats(Context c) {
ffContext = c;
}
public Stats open() throws SQLException {
ffHelper = new DbHelper(ffContext);
ffDatabase = ffHelper.getWritableDatabase();
return this;
}
public void close() {
ffHelper.close();
}
public long createEntry(String weight, String waist, String chest, String legs, String arms) {
ContentValues cv = new ContentValues();
cv.put(KEY_WEIGHT, weight);
cv.put(KEY_WAIST, waist);
cv.put(KEY_CHEST, chest);
cv.put(KEY_LEGS, legs);
cv.put(KEY_ARMS, arms);
return ffDatabase.insert(DATABASE_TABLE, null, cv);
}
public String getData() {
String[] columns = new String[] { KEY_ROWID, KEY_WEIGHT, KEY_WAIST, KEY_CHEST, KEY_LEGS, KEY_ARMS };
Cursor c = ffDatabase.query(DATABASE_TABLE, columns, null, null, null,
null, null);
String result = "";
int iRow = c.getColumnIndex(KEY_ROWID);
int iWeight = c.getColumnIndex(KEY_WEIGHT);
int iWaist = c.getColumnIndex(KEY_WAIST);
int iChest = c.getColumnIndex(KEY_CHEST);
int iLegs = c.getColumnIndex(KEY_LEGS);
int iArms = c.getColumnIndex(KEY_ARMS);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result + c.getString(iRow) + " " + c.getString(iWeight)
+ " " + c.getString(iWaist)
+ " " + c.getString(iChest)
+ " " + c.getString(iLegs)
+ " " + c.getString(iArms) + "\n";
}
return result;
}
}
and below is the Activity that calls the SQL handling class:
package com.uhi.fatfighter;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
public class DBView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.view_stats);
TextView tv = (TextView) findViewById(R.id.tvDBInfo);
Stats dbInfo = new Stats(this);
dbInfo.open();
String data = dbInfo.getData();
dbInfo.close();
if (!TextUtils.isEmpty(data)) {
tv.setText(data);
}
}
}
as i said this was working fine until I added some extra fields
Logcat:
05-09 13:44:32.761: E/Trace(7576): error opening trace file: No such file or directory (2)
05-09 13:44:32.894: E/InputDispatcher(1294): channel '415d5068 com.uhi.fatfighter/com.uhi.fatfighter.Splash (server)' ~ Channel is unrecoverably broken and will be disposed!
05-09 13:44:34.964: E/Trace(7593): error opening trace file: No such file or directory (2)
05-09 13:44:34.988: E/Trace(7598): error opening trace file: No such file or directory (2)
05-09 13:44:54.250: E/AndroidRuntime(7598): FATAL EXCEPTION: main
05-09 13:44:54.250: E/AndroidRuntime(7598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uhi.fatfighter/com.uhi.fatfighter.DBView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.os.Looper.loop(Looper.java:137)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.main(ActivityThread.java:4928)
05-09 13:44:54.250: E/AndroidRuntime(7598): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:44:54.250: E/AndroidRuntime(7598): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-09 13:44:54.250: E/AndroidRuntime(7598): at dalvik.system.NativeStart.main(Native Method)
05-09 13:44:54.250: E/AndroidRuntime(7598): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.Activity.setContentView(Activity.java:1867)
05-09 13:44:54.250: E/AndroidRuntime(7598): at com.uhi.fatfighter.DBView.onCreate(DBView.java:16)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:44:54.250: E/AndroidRuntime(7598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-09 13:44:54.250: E/AndroidRuntime(7598): ... 11 more
05-09 13:44:56.765: E/Trace(7630): error opening trace file: No such file or directory (2)
05-09 13:45:10.125: E/Trace(7649): error opening trace file: No such file or directory (2)
05-09 13:45:10.433: E/Trace(7664): error opening trace file: No such file or directory (2)
05-09 13:45:11.183: E/Trace(7678): error opening trace file: No such file or directory (2)
05-09 13:45:12.203: E/Trace(7695): error opening trace file: No such file or directory (2)
05-09 13:45:14.187: E/AndroidRuntime(7630): FATAL EXCEPTION: main
05-09 13:45:14.187: E/AndroidRuntime(7630): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uhi.fatfighter/com.uhi.fatfighter.DBView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.os.Looper.loop(Looper.java:137)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.main(ActivityThread.java:4928)
05-09 13:45:14.187: E/AndroidRuntime(7630): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:45:14.187: E/AndroidRuntime(7630): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-09 13:45:14.187: E/AndroidRuntime(7630): at dalvik.system.NativeStart.main(Native Method)
05-09 13:45:14.187: E/AndroidRuntime(7630): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.Activity.setContentView(Activity.java:1867)
05-09 13:45:14.187: E/AndroidRuntime(7630): at com.uhi.fatfighter.DBView.onCreate(DBView.java:16)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:45:14.187: E/AndroidRuntime(7630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-09 13:45:14.187: E/AndroidRuntime(7630): ... 11 more
05-09 13:45:18.433: E/Trace(7722): error opening trace file: No such file or directory (2)
05-09 13:52:02.109: E/Trace(7767): error opening trace file: No such file or directory (2)
05-09 13:52:03.554: E/Trace(7781): error opening trace file: No such file or directory (2)
05-09 13:55:06.617: E/Trace(7807): error opening trace file: No such file or directory (2)
05-09 13:55:26.808: E/AndroidRuntime(7807): FATAL EXCEPTION: main
05-09 13:55:26.808: E/AndroidRuntime(7807): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.uhi.fatfighter/com.uhi.fatfighter.DBView}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.os.Looper.loop(Looper.java:137)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.main(ActivityThread.java:4928)
05-09 13:55:26.808: E/AndroidRuntime(7807): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:55:26.808: E/AndroidRuntime(7807): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-09 13:55:26.808: E/AndroidRuntime(7807): at dalvik.system.NativeStart.main(Native Method)
05-09 13:55:26.808: E/AndroidRuntime(7807): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.view.ViewGroup
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:747)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.Activity.setContentView(Activity.java:1867)
05-09 13:55:26.808: E/AndroidRuntime(7807): at com.uhi.fatfighter.DBView.onCreate(DBView.java:16)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.Activity.performCreate(Activity.java:5008)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-09 13:55:26.808: E/AndroidRuntime(7807): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-09 13:55:26.808: E/AndroidRuntime(7807): ... 11 more
05-09 13:58:40.242: E/Trace(7828): error opening trace file: No such file or directory (2)
05-09 13:58:40.500: E/Trace(7841): error opening trace file: No such file or directory (2)
05-09 13:58:40.937: E/PhotoDatabaseHelper(7828): query fail: empty cursor: android.database.sqlite.SQLiteCursor#415ae7e8
05-09 13:58:40.937: E/WidgetProvider(7828): cannot load widget: 5
I can see the class is having trouble casting TextView
DROP TABLE IF EXISTS
is the correct syntax.
Your drop query is wrong. EXIST is a wrong keyword.
It should be :
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
The problem lies in the XML file for the SQLITE view, I checked all my TextView fields were set up correctly, they weren't. This fixed the issue.
Am I doing this right? I'm trying to implement a simple countdown timer just to get my feet of the ground with it.
my timer class is not nested in my activity, and all by itself in it's own java file, for the sake of neatness. here:
public class McatTimer extends CountDownTimer {
private TextView timer_tv;
public McatTimer(long millisInFuture, long countDownInterval, TextView textview) {
super(millisInFuture, countDownInterval);
this.timer_tv = textview;
}
#Override
public void onFinish() {
timer_tv.setText("DONE!");
}
#Override
public void onTick(long millisUntilFinished) {
timer_tv.setText("seconds remaining: " + millisUntilFinished / 1000);
}
}
and here is logcat:
10-03 08:40:36.007: E/AndroidRuntime(2582): FATAL EXCEPTION: main
10-03 08:40:36.007: E/AndroidRuntime(2582): java.lang.NullPointerException
10-03 08:40:36.007: E/AndroidRuntime(2582): at com.mangodeveloper.mcathomie.McatTimer.onTick(McatTimer.java:22)
10-03 08:40:36.007: E/AndroidRuntime(2582): at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:124)
10-03 08:40:36.007: E/AndroidRuntime(2582): at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 08:40:36.007: E/AndroidRuntime(2582): at android.os.Looper.loop(Looper.java:123)
10-03 08:40:36.007: E/AndroidRuntime(2582): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-03 08:40:36.007: E/AndroidRuntime(2582): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 08:40:36.007: E/AndroidRuntime(2582): at java.lang.reflect.Method.invoke(Method.java:507)
10-03 08:40:36.007: E/AndroidRuntime(2582): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-03 08:40:36.007: E/AndroidRuntime(2582): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-03 08:40:36.007: E/AndroidRuntime(2582): at dalvik.system.NativeStart.main(Native Method)
and my activity has these in their appropriate places:
private McatTimer mcatTimer;
....
mcatTimer = new McatTimer(GAME_PREFERENCES_ROUNDTIME*1000, 1000, timerTv);
mcatTimer.start();
Also is there some trick to reading these logcats? I'm sorry but i'm self-teaching.
Looks like your TextView object is null. Please ensure that you have intialized your TextView before you call the
mcatTimer = new McatTimer(GAME_PREFERENCES_ROUNDTIME*1000, 1000, timerTv);
Call this,
timerTv=(TextView)findViewById(R.id.textview);
I'm calling a dialog function on my code, but everytime I test it it makes a force close...
Here's my code:
public void onLongPressFinished(MotionEvent arg0,
ManagedOverlay arg1, GeoPoint arg2, ManagedOverlayItem item) {
if (item!= null) // if the user longpresses a marker, it will pop up the route dialog
{
RouteDialog dialog = new RouteDialog();
dialog.showCustomDialog();
}
and the class I use to implement the dialog:
package com.BuStopTracker;
import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class RouteDialog extends Activity{
public void showCustomDialog(){
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.routetodialog);//loads layout from xml file
dialog.setTitle("TÃtulo do custom dialog");
final Button ok = (Button) dialog.findViewById(R.id.bt_ok);
final Button cancelar = (Button) dialog.findViewById(R.id.bt_cancel);
final EditText editText = (EditText) dialog.findViewById(R.id.inputText);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//OK button action
}
});
cancelar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
I know that my "LongPress detector" function is working, because I tested it with a toast, and it worked fine...
So, can someone help me? I'm pretty sure my fault is in the way I call the dialog, I just can't see why or where...
Thanks.
PS: As requested, here's the logcat:
11-13 20:13:54.789: D/dalvikvm(406): GC_CONCURRENT freed 1153K, 54% free 3159K/6727K, external 2002K/2137K, paused 4ms+4ms
11-13 20:13:55.109: D/dalvikvm(406): GC_CONCURRENT freed 616K, 51% free 3363K/6727K, external 2002K/2137K, paused 5ms+7ms
11-13 20:13:55.369: D/dalvikvm(406): GC_EXTERNAL_ALLOC freed 721K, 54% free 3116K/6727K, external 2121K/2137K, paused 52ms
11-13 20:13:55.829: I/MapActivity(406): Handling network change notification:CONNECTED
11-13 20:13:55.829: E/MapActivity(406): Couldn't get connection factory client
11-13 20:13:55.979: D/dalvikvm(406): GC_EXTERNAL_ALLOC freed 215K, 56% free 3020K/6727K, external 2440K/2692K, paused 77ms
11-13 20:14:17.679: D/AndroidRuntime(406): Shutting down VM
11-13 20:14:17.679: W/dalvikvm(406): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-13 20:14:17.719: E/AndroidRuntime(406): FATAL EXCEPTION: main
11-13 20:14:17.719: E/AndroidRuntime(406): java.lang.IllegalStateException: System services not available to Activities before onCreate()
11-13 20:14:17.719: E/AndroidRuntime(406): at android.app.Activity.getSystemService(Activity.java:3536)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.app.Dialog.<init>(Dialog.java:141)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.app.Dialog.<init>(Dialog.java:123)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.BuStopTracker.RouteDialog.showCustomDialog(RouteDialog.java:23)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.BuStopTracker.BusTrackerBetaActivity$7.onLongPressFinished(BusTrackerBetaActivity.java:278)
11-13 20:14:17.719: E/AndroidRuntime(406): at de.android1.overlaymanager.ManagedOverlayGestureDetector.invokeLongPressFinished(ManagedOverlayGestureDetector.java:76)
11-13 20:14:17.719: E/AndroidRuntime(406): at de.android1.overlaymanager.ManagedOverlay.draw(ManagedOverlay.java:79)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.google.android.maps.Overlay.draw(Overlay.java:179)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.google.android.maps.MapView.onDraw(MapView.java:530)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.View.draw(View.java:6880)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.View.draw(View.java:6883)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.View.draw(View.java:6883)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewRoot.draw(ViewRoot.java:1522)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.os.Looper.loop(Looper.java:130)
11-13 20:14:17.719: E/AndroidRuntime(406): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-13 20:14:17.719: E/AndroidRuntime(406): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 20:14:17.719: E/AndroidRuntime(406): at java.lang.reflect.Method.invoke(Method.java:507)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-13 20:14:17.719: E/AndroidRuntime(406): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-13 20:14:17.719: E/AndroidRuntime(406): at dalvik.system.NativeStart.main(Native Method)
11-13 20:14:20.059: I/Process(406): Sending signal. PID: 406 SIG: 9
You should not extend Activity in your RouteDialog. Pass a Context into showCustomDialog or make a contructor taking it and store it in your class.
To fix is easy change this, in RouteDialog:
public class RouteDialog {
public void showCustomDialog(Context context){
final Dialog dialog = new Dialog(context);
/* leave rest as is */
And then change your code to show the dialog to:
RouteDialog dialog = new RouteDialog();
dialog.showCustomDialog(this);