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 );
}
}
Related
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
I'm not getting a direct error in Eclipse.. but when trying to run this on my phone it doesn't open the activity and then my phone resets. I might be using the array adapter wrong.. but here's my code files:
Java File
package creativecoders.periodictable;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AM extends Activity {
private ListView amList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.am);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
#Override
public void onStart() {
super.onStart();
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.AM, android.R.layout.simple_list_item_1);
amList.setAdapter(adapter);
}
public void onPause() {
super.onPause();
finish();
}
public void onStop() {
super.onStop();
finish();
}
public void onDestroy() {
super.onDestroy();
finish();
}
}
XML Layout File
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
String File
<string-array name="AM">
<item> ONE </item>
<item> TWO </item>
<item> THREE </item>
</string-array>
EDIT: Log file:
04-20 23:10:07.660: D/AndroidRuntime(284): Shutting down VM
04-20 23:10:07.660: W/dalvikvm(284): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-20 23:10:07.670: E/AndroidRuntime(284): FATAL EXCEPTION: main
04-20 23:10:07.670: E/AndroidRuntime(284): java.lang.RuntimeException: Unable to start activity ComponentInfo{creativecoders.periodictable/creativecoders.periodictable.AM}: java.lang.NullPointerException
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Handler.dispatchMessage(Handler.java:99)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.os.Looper.loop(Looper.java:123)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invokeNative(Native Method)
04-20 23:10:07.670: E/AndroidRuntime(284): at java.lang.reflect.Method.invoke(Method.java:521)
04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-20 23:10:07.670: E/AndroidRuntime(284): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-20 23:10:07.670: E/AndroidRuntime(284): at dalvik.system.NativeStart.main(Native Method)
04-20 23:10:07.670: E/AndroidRuntime(284): Caused by: java.lang.NullPointerException
04-20 23:10:07.670: E/AndroidRuntime(284): at creativecoders.periodictable.AM.onStart(AM.java:28)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.Activity.performStart(Activity.java:3781)
04-20 23:10:07.670: E/AndroidRuntime(284): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
04-20 23:10:07.670: E/AndroidRuntime(284): ... 11 more
you did not initialize the ListView. in onCreate()
amList = (ListView)findViewById(R.id.listView1);
I want to extract the text from a pdf-file on the internet to a string in java using iText. This is my code:
package me.moop.mytwitter;
import java.io.IOException;
import java.text.ParseException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.app.ProgressDialog;
public class MainActivity extends Activity {
Button mBtnCheck;
EditText mEtxtGroup;
ProgressDialog mProgressDialog;
TextView mTxtv1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nicelayout3);
mBtnCheck = (Button) findViewById(R.id.btnCheck);
mEtxtGroup = (EditText) findViewById(R.id.etxtGroup);
mTxtv1 = (TextView) findViewById(R.id.textView1);
}
public void checkScheduleChange(View view){
if (view == mBtnCheck){
String group;
group = mEtxtGroup.getText().toString();
if (group.length() > 0){
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Bezig met checken voor roosterwijzigingen...");
mProgressDialog.show();
new CheckScheduleChangeTask().execute();
}
else{
Toast.makeText(this, "Voer een klas in", Toast.LENGTH_LONG).show();
}
}
}
private class CheckScheduleChangeTask extends AsyncTask<Void, Void, Void> {
String content;
#Override
protected Void doInBackground(Void... args) {
PdfReader reader = null;
try {
reader = new PdfReader("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
content = PdfTextExtractor.getTextFromPage(reader, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void arg) {
mProgressDialog.dismiss();
String group = mEtxtGroup.getText().toString();
if (content.contains(group)){
Toast.makeText(MainActivity.this, "U hebt een roosterwijziging", Toast.LENGTH_LONG).show();
}
mTxtv1.setText(content);
}
}
}
For the people in a hurry, here's the iText part:
private class CheckScheduleChangeTask extends AsyncTask<Void, Void, Void> {
String content;
#Override
protected Void doInBackground(Void... args) {
PdfReader reader = null;
try {
reader = new PdfReader("http://www.augustinianum.eu/roosterwijzigingen/14062012.pdf");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
content = PdfTextExtractor.getTextFromPage(reader, 1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void arg) {
// more code
}
Whenever I launch this in my emulator I'm getting a fore close after calling the class: CheckScheduleChangeTask. This is the log:
07-27 09:15:08.354: D/ddm-heap(222): Got feature list request
07-27 09:15:12.994: E/dalvikvm(222): Could not find class 'com.itextpdf.text.pdf.PdfReader', referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:15:13.004: W/dalvikvm(222): VFY: unable to resolve new-instance 410 (Lcom/itextpdf/text/pdf/PdfReader;) in Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;
07-27 09:15:13.004: D/dalvikvm(222): VFY: replacing opcode 0x22 at 0x0002
07-27 09:15:13.004: D/dalvikvm(222): Making a copy of Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;.doInBackground code (137 bytes)
07-27 09:15:13.004: E/dalvikvm(222): Could not find class 'com.itextpdf.text.pdf.parser.PdfReaderContentParser', referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:15:13.004: W/dalvikvm(222): VFY: unable to resolve new-instance 411 (Lcom/itextpdf/text/pdf/parser/PdfReaderContentParser;) in Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;
07-27 09:15:13.004: D/dalvikvm(222): VFY: replacing opcode 0x22 at 0x000a
07-27 09:15:13.045: W/dalvikvm(222): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
07-27 09:15:13.045: E/AndroidRuntime(222): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
07-27 09:15:13.135: E/AndroidRuntime(222): java.lang.RuntimeException: An error occured while executing doInBackground()
07-27 09:15:13.135: E/AndroidRuntime(222): at android.os.AsyncTask$3.done(AsyncTask.java:200)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.lang.Thread.run(Thread.java:1096)
07-27 09:15:13.135: E/AndroidRuntime(222): Caused by: java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
07-27 09:15:13.135: E/AndroidRuntime(222): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:84)
07-27 09:15:13.135: E/AndroidRuntime(222): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:1)
07-27 09:15:13.135: E/AndroidRuntime(222): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-27 09:15:13.135: E/AndroidRuntime(222): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-27 09:15:13.135: E/AndroidRuntime(222): ... 4 more
07-27 09:15:13.164: I/dalvikvm(222): threadid=7: reacting to signal 3
07-27 09:15:13.394: I/dalvikvm(222): Wrote stack trace to '/data/anr/traces.txt'
07-27 09:15:16.894: I/Process(222): Sending signal. PID: 222 SIG: 9
07-27 09:17:59.094: E/dalvikvm(252): Could not find class 'com.itextpdf.text.pdf.PdfReader', referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:17:59.094: W/dalvikvm(252): VFY: unable to resolve new-instance 410 (Lcom/itextpdf/text/pdf/PdfReader;) in Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;
07-27 09:17:59.094: D/dalvikvm(252): VFY: replacing opcode 0x22 at 0x0002
07-27 09:17:59.094: D/dalvikvm(252): Making a copy of Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;.doInBackground code (137 bytes)
07-27 09:17:59.094: E/dalvikvm(252): Could not find class 'com.itextpdf.text.pdf.parser.PdfReaderContentParser', referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:17:59.094: W/dalvikvm(252): VFY: unable to resolve new-instance 411 (Lcom/itextpdf/text/pdf/parser/PdfReaderContentParser;) in Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;
07-27 09:17:59.094: D/dalvikvm(252): VFY: replacing opcode 0x22 at 0x000a
07-27 09:17:59.124: W/dalvikvm(252): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
07-27 09:17:59.124: E/AndroidRuntime(252): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
07-27 09:17:59.134: E/AndroidRuntime(252): java.lang.RuntimeException: An error occured while executing doInBackground()
07-27 09:17:59.134: E/AndroidRuntime(252): at android.os.AsyncTask$3.done(AsyncTask.java:200)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.lang.Thread.run(Thread.java:1096)
07-27 09:17:59.134: E/AndroidRuntime(252): Caused by: java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
07-27 09:17:59.134: E/AndroidRuntime(252): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:70)
07-27 09:17:59.134: E/AndroidRuntime(252): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:1)
07-27 09:17:59.134: E/AndroidRuntime(252): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-27 09:17:59.134: E/AndroidRuntime(252): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-27 09:17:59.134: E/AndroidRuntime(252): ... 4 more
07-27 09:17:59.521: I/dalvikvm(252): threadid=7: reacting to signal 3
07-27 09:17:59.794: I/dalvikvm(252): Wrote stack trace to '/data/anr/traces.txt'
07-27 09:18:02.743: I/Process(252): Sending signal. PID: 252 SIG: 9
07-27 09:26:26.713: E/dalvikvm(280): Could not find class 'com.itextpdf.text.pdf.PdfReader', referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:26:26.723: W/dalvikvm(280): VFY: unable to resolve new-instance 410 (Lcom/itextpdf/text/pdf/PdfReader;) in Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;
07-27 09:26:26.723: D/dalvikvm(280): VFY: replacing opcode 0x22 at 0x0001
07-27 09:26:26.723: D/dalvikvm(280): Making a copy of Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;.doInBackground code (93 bytes)
07-27 09:26:26.723: I/dalvikvm(280): Could not find method com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage, referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:26:26.723: W/dalvikvm(280): VFY: unable to resolve static method 2969: Lcom/itextpdf/text/pdf/parser/PdfTextExtractor;.getTextFromPage (Lcom/itextpdf/text/pdf/PdfReader;I)Ljava/lang/String;
07-27 09:26:26.723: D/dalvikvm(280): VFY: replacing opcode 0x71 at 0x000a
07-27 09:26:26.754: W/dalvikvm(280): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
07-27 09:26:26.754: E/AndroidRuntime(280): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
07-27 09:26:26.763: E/AndroidRuntime(280): java.lang.RuntimeException: An error occured while executing doInBackground()
07-27 09:26:26.763: E/AndroidRuntime(280): at android.os.AsyncTask$3.done(AsyncTask.java:200)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.lang.Thread.run(Thread.java:1096)
07-27 09:26:26.763: E/AndroidRuntime(280): Caused by: java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
07-27 09:26:26.763: E/AndroidRuntime(280): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:68)
07-27 09:26:26.763: E/AndroidRuntime(280): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:1)
07-27 09:26:26.763: E/AndroidRuntime(280): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-27 09:26:26.763: E/AndroidRuntime(280): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-27 09:26:26.763: E/AndroidRuntime(280): ... 4 more
07-27 09:26:27.063: I/dalvikvm(280): threadid=7: reacting to signal 3
07-27 09:26:27.404: I/dalvikvm(280): Wrote stack trace to '/data/anr/traces.txt'
07-27 09:46:50.573: E/dalvikvm(308): Could not find class 'com.itextpdf.text.pdf.PdfReader', referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:46:50.573: W/dalvikvm(308): VFY: unable to resolve new-instance 410 (Lcom/itextpdf/text/pdf/PdfReader;) in Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;
07-27 09:46:50.573: D/dalvikvm(308): VFY: replacing opcode 0x22 at 0x0001
07-27 09:46:50.573: D/dalvikvm(308): Making a copy of Lme/moop/mytwitter/MainActivity$CheckScheduleChangeTask;.doInBackground code (97 bytes)
07-27 09:46:50.573: I/dalvikvm(308): Could not find method com.itextpdf.text.pdf.parser.PdfTextExtractor.getTextFromPage, referenced from method me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground
07-27 09:46:50.573: W/dalvikvm(308): VFY: unable to resolve static method 2969: Lcom/itextpdf/text/pdf/parser/PdfTextExtractor;.getTextFromPage (Lcom/itextpdf/text/pdf/PdfReader;I)Ljava/lang/String;
07-27 09:46:50.583: D/dalvikvm(308): VFY: replacing opcode 0x71 at 0x000a
07-27 09:46:50.624: W/dalvikvm(308): threadid=15: thread exiting with uncaught exception (group=0x4001b188)
07-27 09:46:50.624: E/AndroidRuntime(308): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception
07-27 09:46:50.634: E/AndroidRuntime(308): java.lang.RuntimeException: An error occured while executing doInBackground()
07-27 09:46:50.634: E/AndroidRuntime(308): at android.os.AsyncTask$3.done(AsyncTask.java:200)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.lang.Thread.run(Thread.java:1096)
07-27 09:46:50.634: E/AndroidRuntime(308): Caused by: java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
07-27 09:46:50.634: E/AndroidRuntime(308): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:68)
07-27 09:46:50.634: E/AndroidRuntime(308): at me.moop.mytwitter.MainActivity$CheckScheduleChangeTask.doInBackground(MainActivity.java:1)
07-27 09:46:50.634: E/AndroidRuntime(308): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-27 09:46:50.634: E/AndroidRuntime(308): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-27 09:46:50.634: E/AndroidRuntime(308): ... 4 more
07-27 09:46:51.105: I/dalvikvm(308): threadid=7: reacting to signal 3
07-27 09:46:51.423: I/dalvikvm(308): Wrote stack trace to '/data/anr/traces.txt'
07-27 09:46:54.444: I/Process(308): Sending signal. PID: 308 SIG: 9
It seems like there's something wrong with the imports. Does anyone know how to fix this?
THANK YOU!
It did it using iText, it's extremely easy. However, if someone has a question about it, just ask me.
BTW The solution of the question above is here:
https://stackoverflow.com/a/10046725/1289716
You can use this simple example of creating pdf from text :)
Use the library droidtext0.2jar .. available on the site .
Edited
you added your library to build path ? If not then add it .
You might need to import these as well:
import com.lowagie.text.BadElementException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
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);
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);