I am trying to create an app using text to speech. Whenever I move from activity Text_entry to activity CombChange and back i receive these service connection leaked errors in the log cat (below).
Can anyone see why?
I have only pasted the relevant bits of the Text_Entry and CombChange classes - so there may be missing declarations and curly brackets etc.
public class Text_entry extends Activity implements OnTouchListener, TextToSpeech.OnInitListener{
speech = new Speech(this);
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
Intent intent2 = new Intent(this, CombChange.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent2.putExtra("newPat", enteredNumber);
startActivity(intent2);
}
#Override
public void onResume() {
super.onResume();
Intent intent = getIntent();
String hc =" ";
hc = intent.getExtras().getString("helpComb");
if (hc.equals("true"))
helpComb = true;
else
helpComb = false;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
speech = new Speech(this);
}
else {
Intent installTTSIntent = new Intent();
installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installTTSIntent);
}
}
}
.
public class CombChange extends ListActivity {
speech = new Speech(this);
speech.changeText("enter the new combination");
speech.speaks();
SystemClock.sleep(1300);
Intent intent = new Intent(this, Text_entry.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("helpComb", "true");
speech.cleanUp();
startActivity(intent);
}
.
public class Speech implements TextToSpeech.OnInitListener {
private String toRead;
private TextToSpeech tts;
public Speech(Context c) {
tts = new TextToSpeech(c, this);
tts.setPitch(1.2f);
tts.setSpeechRate(1.5f);
}
public void speaks()
{
speakOut();
}
public void changeText(String changeTo)
{
toRead = changeTo;
}
public void cleanUp() {
//Don't forget to shutdown tts!
if (tts != null) {
tts.stop();
tts.shutdown();
}
}
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.UK);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
protected void onStop()
{
if(tts != null){
tts.shutdown();
}
}
private void speakOut() {
tts.speak(toRead, TextToSpeech.QUEUE_FLUSH, null);
}
}
.
03-21 16:42:32.515: I/TextToSpeech(24023): Sucessfully bound to com.google.android.tts
03-21 16:42:32.535: E/ActivityThread(24023): Activity org.BT.Text_entry has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection#427fd290 that was originally bound here
03-21 16:42:32.535: E/ActivityThread(24023): android.app.ServiceConnectionLeaked: Activity org.BT.Text_entry has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection#427fd290 that was originally bound here
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:965)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:859)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ContextImpl.bindService(ContextImpl.java:1344)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ContextImpl.bindService(ContextImpl.java:1336)
03-21 16:42:32.535: E/ActivityThread(24023): at android.content.ContextWrapper.bindService(ContextWrapper.java:401)
03-21 16:42:32.535: E/ActivityThread(24023): at android.speech.tts.TextToSpeech.connectToEngine(TextToSpeech.java:627)
03-21 16:42:32.535: E/ActivityThread(24023): at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:597)
03-21 16:42:32.535: E/ActivityThread(24023): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:553)
03-21 16:42:32.535: E/ActivityThread(24023): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:527)
03-21 16:42:32.535: E/ActivityThread(24023): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:512)
03-21 16:42:32.535: E/ActivityThread(24023): at org.BT.Speech.<init>(Speech.java:14)
03-21 16:42:32.535: E/ActivityThread(24023): at org.BT.Text_entry.onCreate(Text_entry.java:97)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.Activity.performCreate(Activity.java:5184)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-21 16:42:32.535: E/ActivityThread(24023): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 16:42:32.535: E/ActivityThread(24023): at android.os.Looper.loop(Looper.java:137)
03-21 16:42:32.535: E/ActivityThread(24023): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-21 16:42:32.535: E/ActivityThread(24023): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 16:42:32.535: E/ActivityThread(24023): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 16:42:32.535: E/ActivityThread(24023): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-21 16:42:32.535: E/ActivityThread(24023): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-21 16:42:32.535: E/ActivityThread(24023): at dalvik.system.NativeStart.main(Native Method)
03-21 16:42:32.670: I/TextToSpeech(24023): Sucessfully bound to com.google.android.tts
03-21 16:42:32.670: D/(24023): 3333333333333333333333333333333333333333333333333
03-21 16:42:32.670: E/SpannableStringBuilder(24023): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-21 16:42:32.670: E/SpannableStringBuilder(24023): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-21 16:42:32.775: I/TextToSpeech(24023): Connected to TTS Service
03-21 16:42:32.780: I/TextToSpeech(24023): Connected to TTS Service
I believe this can solve your problem, however I cannot explain it in terms of your code - maybe someone else on here can
http://www.stevenmarkford.com/android-activity-has-leaked-serviceconnection-that-was-originally-bound-here/
I am not sure how much this will help but Please try to implement onPause() method in Activity class. And unbind your service explicitly.
For ex:
#Override
protected void onPause() {
super.onPause();
CalculatorUser c=new CalculatorUser(); //your Activity name object
c.unbindService((ServiceConnection) this);
}
Unbinding might solve your issue and "Activity 'APP' has leaked ServiceConnection" happens mostly when you move out of your Activity So you need to explicitly tell to Android OS to please unbind me from services my Activity is using as of now. When again you will launch you App it will bind to service. If its not helpful sent me code i will try to fix it for you.
ACTUAL ANSWER TO THIS PROBLEM:
You need to call destroy() on your TextToSpeech object when the service is destroyed.
I had this problem and saw your question so I thought I would answer it for anyone else who comes here.
For me works to shutdown the TextToSpeech object.
#Override
protected void onDestroy() {
tts.shutdown();
super.onDestroy();
}
Related
I need your help, there is an Fatal Error in my code. I don't know how to solve this problem... please help me out :)
my code
public class MainActivity extends Activity {
// button to show progress dialog
Button btnShowProgress;
// Progress Dialog
private ProgressDialog pDialog;
ImageView my_image;
// Progress dialog type (0 - for Horizontal progress bar)
public static final int progress_bar_type = 0;
// File url to download
private static String file_url = "https://example.pdf";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// show progress bar button
btnShowProgress = (Button) findViewById(R.id.btnProgressBar);
// Image view to show image after downloading
my_image = (ImageView) findViewById(R.id.my_image);
/**
* Show Progress bar click event
* */
btnShowProgress.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// starting new Async Task
new DownloadFileFromURL().execute(file_url);
}
});
}
/**
* Showing Dialog
* */
#Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type: // we set this to 0
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}
/**
* Background Async Task to download file
* */
class DownloadFileFromURL extends AsyncTask<String, String, String> {
private SSLContext context;
/**
* Before starting background thread
* Show Progress Bar Dialog
* */
#Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
/**
* Downloading file in background thread
* */
#Override
protected String doInBackground(String... f_url) {
int count;
try {
This line is the error in: URL url = new URL(f_url[0]);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
// Load the truststore that includes self-signed cert as a "trusted" entry.
KeyStore truststore;
truststore = KeyStore.getInstance("BKS");
InputStream in = getActivity().getResources().openRawResource(R.raw.mykeystore);
truststore.load(in, "mysecret".toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(truststore);
// Create custom SSL context that incorporates that truststore
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int lenghtOfFile = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(connection.getInputStream(), 8192);
// Output stream
OutputStream output = new FileOutputStream("/sdcard/downloadedfile.pdf");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress(""+(int)((total*100)/lenghtOfFile));
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
private ContextWrapper getActivity() {
// TODO Auto-generated method stub
return null;
}
/**
* Updating progress bar
* */
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}
/**
* After completing background task
* Dismiss the progress dialog
* **/
#Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);
// Displaying downloaded image into image view
// Reading image path from sdcard
String imagePath = Environment.getExternalStorageDirectory().toString() + "/downloadedfile.pdf";
// setting downloaded into image view
my_image.setImageDrawable(Drawable.createFromPath(imagePath));
}
}
}
and this is my Logcat :
03-21 16:36:26.747: E/AndroidRuntime(5751): FATAL EXCEPTION: AsyncTask #1
03-21 16:36:26.747: E/AndroidRuntime(5751): Process: com.example.test2, PID: 5751
03-21 16:36:26.747: E/AndroidRuntime(5751): java.lang.RuntimeException: An error occured while executing doInBackground()
03-21 16:36:26.747: E/AndroidRuntime(5751): at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-21 16:36:26.747: E/AndroidRuntime(5751): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.lang.Thread.run(Thread.java:841)
03-21 16:36:26.747: E/AndroidRuntime(5751): Caused by: java.lang.NullPointerException: println needs a message
03-21 16:36:26.747: E/AndroidRuntime(5751): at android.util.Log.println_native(Native Method)
03-21 16:36:26.747: E/AndroidRuntime(5751): at android.util.Log.e(Log.java:232)
03-21 16:36:26.747: E/AndroidRuntime(5751): at com.example.test1.MainActivity$DownloadFileFromURL.doInBackground(MainActivity.java:194)
03-21 16:36:26.747: E/AndroidRuntime(5751): at com.example.test1.MainActivity$DownloadFileFromURL.doInBackground(MainActivity.java:1)
03-21 16:36:26.747: E/AndroidRuntime(5751): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-21 16:36:26.747: E/AndroidRuntime(5751): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-21 16:36:26.747: E/AndroidRuntime(5751): ... 4 more
Stacktrace output
03-21 18:39:45.957: W/System.err(2061): java.lang.NullPointerException
03-21 18:39:45.967: W/System.err(2061): at com.example.test1.MainActivity$DownloadFileFromURL.doInBackground(MainActivity.java:147)
03-21 18:39:45.967: W/System.err(2061): at com.example.test1.MainActivity$DownloadFileFromURL.doInBackground(MainActivity.java:1)
03-21 18:39:45.967: W/System.err(2061): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-21 18:39:45.967: W/System.err(2061): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-21 18:39:45.967: W/System.err(2061): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-21 18:39:45.967: W/System.err(2061): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-21 18:39:45.967: W/System.err(2061): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-21 18:39:45.967: W/System.err(2061): at java.lang.Thread.run(Thread.java:841)
Try
Log.e("Error:", " " + e.getMessage());
Instead of Log.e("Error: ", e.getMessage());
// e.getMessage() could be null or empty.
Also add catch(MalformedURLException e) {} and see why the url exception is thrown
Make your AsyncTask extend AsyncTask<String, Void, String>.
public class Rating {
private String _id;
private String _rating;
public Rating(){
}
public Rating(String id, String ration){
this._id = id;
this._rating = ration;
}
public Rating(String ration){
this._rating= ration;
}
public String getID(){
return _id;
}
public void setID(String id){
this._id = id;
}
public String getRating(){
return _rating;
}
public void setRating(String rating){
this._rating= rating;
}
#Override
public String toString(){
return _rating;
}
}
///////////////////////////////////////////////////
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME ="ratings.db";
public static final String DATABASE_TABLE ="ratings";
public static final String COLUMN_ID = "id";
public static final String COLUMN_RATING = "rating";
private static final String DATABASE_CREATE = "create table "
+ DATABASE_TABLE + "(" +
COLUMN_ID + " integer primary key autoincrement, " +
COLUMN_RATING + " text not null);";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DatabaseHandler.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);
}
///////////////////////////////////////////////////
public class RatingDataSource {
private SQLiteDatabase database;
private DatabaseHandler dbHelper;
private String[] allColumns = { DatabaseHandler.COLUMN_ID,
DatabaseHandler.COLUMN_RATING };
public RatingDataSource(Context context) {
dbHelper = new DatabaseHandler(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public void addRating(Rating rating) {
SQLiteDatabase db=dbHelper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put(DatabaseHandler.COLUMN_ID,rating.getID());
values.put(DatabaseHandler.COLUMN_RATING, rating.getRating());
database.insert(dbHelper.DATABASE_TABLE,null,values);
db.insert(dbHelper.DATABASE_TABLE,null,values);
db.close();
}
public Rating getRating(String id)
{
SQLiteDatabase db=dbHelper.getWritableDatabase();
Cursor cursor=db.query(dbHelper.DATABASE_TABLE,new String[]{dbHelper.COLUMN_ID,dbHelper.COLUMN_RATING},dbHelper.COLUMN_ID +"=?" ,new String[]{String.valueOf(id)},null,null,null,null);
if (cursor!=null)
cursor.moveToFirst();
Rating rating=new Rating((cursor.getString(0)),cursor.getString(1));
return rating;
}
public void deleteRating(Rating rating) {
SQLiteDatabase db=dbHelper.getReadableDatabase();
db.delete(dbHelper.DATABASE_TABLE,dbHelper.COLUMN_ID+"?",new String[]{String.valueOf(rating.getID())});
db.close();
}
public List<Rating> getAllRating()
{
List<Rating> RatingList=new ArrayList<Rating>();
Cursor cursor = database.query(DatabaseHandler.DATABASE_TABLE, allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Rating rating = cursorToRating(cursor);
RatingList.add(rating);
cursor.moveToNext();
}
cursor.close();
return RatingList;
}
private Rating cursorToRating(Cursor cursor){
Rating rating = new Rating();
rating.setID(cursor.getString(0));
rating.setRating(cursor.getString(1));
return rating;
}
}
//////////////this is my error
03-04 10:59:47.473: INFO/ActivityManager(277): START u0 {cmp=com.example.sampleebook/.GhasidesingelItem (has extras)} from pid 4030
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: ERROR/libEGL(36): called unimplemented OpenGL ES API
03-04 10:59:47.483: WARN/WindowManager(277): Failure taking screenshot for (246x410) to layer 21020
03-04 10:59:47.934: DEBUG/dalvikvm(4030): GC_CONCURRENT freed 270K, 7% free 5878K/6312K, paused 75ms+27ms, total 192ms
03-04 10:59:48.113: DEBUG/AndroidRuntime(4030): Shutting down VM
03-04 10:59:48.113: WARN/dalvikvm(4030): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
03-04 10:59:48.173: ERROR/AndroidRuntime(4030): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sampleebook/com.example.sampleebook.GhasidesingelItem}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
at com.example.sampleebook.RatingDataSource.getRating(RatingDataSource.java:46)
at com.example.sampleebook.GhasidesingelItem.onCreate(GhasidesingelItem.java:81)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more
03-04 10:59:48.263: WARN/ActivityManager(277): Force finishing activity com.example.sampleebook/.GhasidesingelItem
03-04 10:59:48.273: WARN/ActivityManager(277): Force finishing activity com.example.sampleebook/.Ghasideh
03-04 10:59:48.643: INFO/Choreographer(277): Skipped 49 frames! The application may be doing too much work on its main thread.
03-04 10:59:48.643: ERROR/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
03-04 10:59:48.783: WARN/ActivityManager(277): Activity pause timeout for ActivityRecord{410dc930 u0 com.example.sampleebook/.GhasidesingelItem}
03-04 10:59:57.523: WARN/ActivityManager(277): Launch timeout has expired, giving up wake lock!
03-04 10:59:57.523: WARN/ActivityManager(277): Activity idle timeout for ActivityRecord{410dc930 u0 com.example.sampleebook/.GhasidesingelItem}
03-04 10:59:58.857: WARN/ActivityManager(277): Activity idle timeout for ActivityRecord{40f7c650 u0 com.example.sampleebook/.MyActivity}
03-04 11:00:07.615: WARN/ActivityManager(277): Activity destroy timeout for ActivityRecord{4108c680 u0 com.example.sampleebook/.Ghasideh}
03-04 11:00:07.615: WARN/ActivityManager(277): Activity destroy timeout for ActivityRecord{410dc930 u0 com.example.sampleebook/.GhasidesingelItem}
03-04 11:00:23.171: DEBUG/ExchangeService(670): Received deviceId from Email app: null
03-04 11:00:23.171: DEBUG/ExchangeService(670): !!! deviceId unknown; stopping self and retrying
03-04 11:00:28.223: DEBUG/ExchangeService(670): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
03-04 11:00:28.233: WARN/ActivityManager(277): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
03-04 11:00:28.233: DEBUG/ExchangeService(670): !!! Email application not found; stopping self
03-04 11:00:28.254: WARN/ActivityManager(277): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
03-04 11:00:28.254: ERROR/ActivityThread(670): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40d3ebb8 that was originally bound here
android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40d3ebb8 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
at android.app.ContextImpl.bindService(ContextImpl.java:1418)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
03-04 11:00:28.264: ERROR/StrictMode(670): null
android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40d3ebb8 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
at android.app.ContextImpl.bindService(ContextImpl.java:1418)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
03-04 11:00:28.274: WARN/ActivityManager(277): Unbind failed: could not find connection for android.os.BinderProxy#4109ae40
03-04 11:00:28.274: ERROR/ActivityThread(670): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40cf11b8 that was originally bound here
android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40cf11b8 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
at android.app.ContextImpl.bindService(ContextImpl.java:1418)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
03-04 11:00:28.294: ERROR/StrictMode(670): null
android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection#40cf11b8 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
at android.app.ContextImpl.bindService(ContextImpl.java:1418)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
03-04 11:00:28.294: WARN/ActivityManager(277): Unbind failed: could not find connection for android.os.BinderProxy#41067308
03-04 11:00:40.103: WARN/ProcessStats(277): Skipping unknown process pid 4067
if (cursor!=null)
cursor.moveToFirst();
Rating rating=new Rating((cursor.getString(0)),cursor.getString(1));
return rating;
Turn it to:
Rating rating = null;
if (cursor.moveToFirst()) {
rating = new Rating((cursor.getString(0)),cursor.getString(1));
}
cursor.close();
return rating;
I have tried to implement Auto Answer in my project using telephony manager and BroadCastReceiver .
Its working fine But Unfortuantly the APP Crashes when i power on mobile again. Herewith I have attached my code and manifest file also.kindly can any one help us for a solution
Code :
AutoAnswerReceiver .java
public class AutoAnswerReceiver extends BroadcastReceiver {
SharedPreferences mPrefs;
static String PREFS_NAMES = "AutoAnswer";
#Override
public void onReceive(Context context, Intent intent) {
mPrefs = context.getSharedPreferences(PREFS_NAMES, 0);
String AutoResult = mPrefs.getString("AutoAnswer", "FALSE");
// Check phone state
String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING) && AutoResult.equals("TRUE"))
{
context.startService(new Intent(context, AutoAnswerIntentService.class));
}
}
**AutoAnswerIntentService**
public class AutoAnswerIntentService extends IntentService {
public AutoAnswerIntentService() {
super("AutoAnswerIntentService");
}
#Override
protected void onHandleIntent(Intent intent) {
Context context = getBaseContext();
// Let the phone ring for a set delay
try {
Thread.sleep(Integer.parseInt("5") * 1000);
} catch (InterruptedException e) {
// We don't really care
}
// Make sure the phone is still ringing
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getCallState() != TelephonyManager.CALL_STATE_RINGING) {
return;
}
// Answer the phone
try {
answerPhoneAidl(context);
}
catch (Exception e) {
e.printStackTrace();
Log.d("AutoAnswer","Error trying to answer using telephony service. Falling back to headset.");
answerPhoneHeadsethook(context);
}
// Enable the speakerphone
enableSpeakerPhone(context);
return;
}
private void enableSpeakerPhone(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setSpeakerphoneOn(true);
}
private void answerPhoneHeadsethook(Context context) {
// Simulate a press of the headset button to pick up the call
Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");
// froyo and beyond trigger on buttonUp instead of buttonDown
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
}
#SuppressWarnings("unchecked")
private void answerPhoneAidl(Context context) throws Exception {
// Set up communication with the telephony service (thanks to Tedd's Droid Tools!)
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService;
telephonyService = (ITelephony)m.invoke(tm);
// Silence the ringer and answer the call!
telephonyService.silenceRinger();
telephonyService.answerRingingCall();
}
}
Manifestfile
<receiver android:name=".AutoAnswerReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
<receiver android:name=".AutoAnswerBootReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="AutoAnswerIntentService" />
It works fine when app is running.But in case of power on stage it shows the error like
ERROR
03-30 09:54:22.013: E/AndroidRuntime(200): Uncaught handler: thread main exiting due to uncaught exception
03-30 09:54:22.023: E/AndroidRuntime(200): java.lang.RuntimeException: Unable to instantiate receiver com.slet.routemytrips.beta.AutoAnswerBootReceiver: java.lang.ClassNotFoundException: com.slet.routemytrips.beta.AutoAnswerBootReceiver in loader dalvik.system.PathClassLoader#43b7dfd8
03-30 09:54:22.023: E/AndroidRuntime(200): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2616)
03-30 09:54:22.023: E/AndroidRuntime(200): at android.app.ActivityThread.access$3100(ActivityThread.java:119)
03-30 09:54:22.023: E/AndroidRuntime(200): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
03-30 09:54:22.023: E/AndroidRuntime(200): at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 09:54:22.023: E/AndroidRuntime(200): at android.os.Looper.loop(Looper.java:123)
03-30 09:54:22.023: E/AndroidRuntime(200): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-30 09:54:22.023: E/AndroidRuntime(200): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 09:54:22.023: E/AndroidRuntime(200): at java.lang.reflect.Method.invoke(Method.java:521)
03-30 09:54:22.023: E/AndroidRuntime(200): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-30 09:54:22.023: E/AndroidRuntime(200): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-30 09:54:22.023: E/AndroidRuntime(200): at dalvik.system.NativeStart.main(Native Method)
03-30 09:54:22.023: E/AndroidRuntime(200): Caused by: java.lang.ClassNotFoundException: com.slet.routemytrips.beta.AutoAnswerBootReceiver in loader dalvik.system.PathClassLoader#43b7dfd8
03-30 09:54:22.023: E/AndroidRuntime(200): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-30 09:54:22.023: E/AndroidRuntime(200): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-30 09:54:22.023: E/AndroidRuntime(200): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-30 09:54:22.023: E/AndroidRuntime(200): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2609)
03-30 09:54:22.023: E/AndroidRuntime(200): ... 10 more
03-30 09:54:22.083: I/Process(51): Sending signal. PID: 200 SIG: 3
03-30 09:54:22.102: I/dalvikvm(200): threadid=7: reacting to signal 3
03-30 09:54:22.102: E/dalvikvm(200): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
Here is the class file that's missing:
Create a file named AutoAnswerBootReceiver.java
package com.example.autoanswer; // Just change the package name to yours
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class AutoAnswerBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
AutoAnswerNotifier notifier = new AutoAnswerNotifier(context);
notifier.updateNotification();
}
}
I am creating an RSS reader application for android 4.0+. I have put the reader code in AsyncTask because of the NetworkOnMainThreadException. The code almost works fine, however one line has an error. This is my code:
Java code:
private class PostTask extends AsyncTask<String, Integer, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String doInBackground(String... params) {
String url=params[0];
headlines = new ArrayList();
links = new ArrayList();
//Download and parse xml feed
headlines = new ArrayList();
links = new ArrayList();
try {
URL url1 = new URL("http://feeds.pcworld.com/pcworld/latestnews");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
// We will get the XML from an input stream
xpp.setInput(getInputStream(url1), "UTF_8");
/* We will parse the XML content looking for the "<title>" tag which appears inside the "<item>" tag.
* However, we should take in consideration that the rss feed name also is enclosed in a "<title>" tag.
* As we know, every feed begins with these lines: "<channel><title>Feed_Name</title>...."
* so we should skip the "<title>" tag which is a child of "<channel>" tag,
* and take in consideration only "<title>" tag which is a child of "<item>"
*
* In order to achieve this, we will make use of a boolean variable.
*/
boolean insideItem = false;
// Returns the type of current event: START_TAG, END_TAG, etc..
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("item")) {
insideItem = true;
} else if (xpp.getName().equalsIgnoreCase("title")) {
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
} else if (xpp.getName().equalsIgnoreCase("link")) {
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
}else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
insideItem=false;
}
eventType = xpp.next(); //move to next element
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "Feed parsed!";
}
#Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
}
}
in this code snippet i get an error:
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Binding data
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
}
Error: The constructor ArrayAdapter(MainActivity.PostTask, int, List) is undefined.
Logcat:
01-26 20:55:53.811: E/AndroidRuntime(1830): FATAL EXCEPTION: AsyncTask #1
01-26 20:55:53.811: E/AndroidRuntime(1830): java.lang.RuntimeException: An error occured while executing doInBackground()
01-26 20:55:53.811: E/AndroidRuntime(1830): at android.os.AsyncTask$3.done(AsyncTask.java:278)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-26 20:55:53.811: E/AndroidRuntime(1830): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.lang.Thread.run(Thread.java:856)
01-26 20:55:53.811: E/AndroidRuntime(1830): Caused by: java.lang.IllegalArgumentException
01-26 20:55:53.811: E/AndroidRuntime(1830): at org.kxml2.io.KXmlParser.setInput(KXmlParser.java:1615)
01-26 20:55:53.811: E/AndroidRuntime(1830): at com.mysoftware.mysoftwareos.mobile.MainActivity$PostTask.doInBackground(MainActivity.java:343)
01-26 20:55:53.811: E/AndroidRuntime(1830): at com.mysoftware.mysoftwareos.mobile.MainActivity$PostTask.doInBackground(MainActivity.java:1)
01-26 20:55:53.811: E/AndroidRuntime(1830): at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-26 20:55:53.811: E/AndroidRuntime(1830): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-26 20:55:53.811: E/AndroidRuntime(1830): ... 5 more
Could anyone please look into my problem and come up with a solution? Or tell me if i should do anything different? Thanks a lot!
Change it to:
ArrayAdapter adapter = new ArrayAdapter(MainActivity.this,
android.R.layout.simple_list_item_1, headlines);
this refers to the AsyncTask, so you have to explicitly reference MainActivity's this.
use Activity Context instead of AsyncTask to Create ArrayAdapter inside onPostExecute method as :
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(Your_Current_Activity.this,
android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
EDIT :
after log posted also change
xpp.setInput(getInputStream(url1), "UTF_8");
to
xpp.setInput(url1.openConnection().getInputStream(), "UTF_8");
Getting java.lang.RuntimeException: Failure delivering result ResultInfo from a NPE apparently resulting from a call in my getRealPathFromURI function.
Video capture works fine, but image capture throws the NPE. Both image and video work fine on my Evo.
03-30 09:34:25.725 D/ZoorniApp( 2509): Handling activity result. requestCode:12345 resultCode:-1
03-30 09:34:25.733 D/AndroidRuntime( 2509): Shutting down VM
03-30 09:34:25.733 W/dalvikvm( 2509): threadid=3: thread exiting with uncaught exception (group=0x4001e2e0)
03-30 09:34:25.733 E/AndroidRuntime( 2509): Uncaught handler: thread main exiting due to uncaught exception
03-30 09:34:25.741 E/AndroidRuntime( 2509): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12345, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.mobile.zoorni/com.mobile.zoorni.ZoorniMobile}: java.lang.NullPointerException
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.deliverResults(ActivityThread.java:3391)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3433)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.access$2900(ActivityThread.java:121)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.os.Handler.dispatchMessage(Handler.java:99)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.os.Looper.loop(Looper.java:136)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.main(ActivityThread.java:4425)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at java.lang.reflect.Method.invokeNative(Native Method)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at java.lang.reflect.Method.invoke(Method.java:521)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at dalvik.system.NativeStart.main(Native Method)
03-30 09:34:25.741 E/AndroidRuntime( 2509): Caused by: java.lang.NullPointerException
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.content.ContentResolver.acquireProvider(ContentResolver.java:757)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.content.ContentResolver.query(ContentResolver.java:200)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.Activity.managedQuery(Activity.java:1495)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.mobile.zoorni.ZoorniMobile.getRealPathFromURI(ZoorniMobile.java:287)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at com.mobile.zoorni.ZoorniMobile.onActivityResult(ZoorniMobile.java:251)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.Activity.dispatchActivityResult(Activity.java:3828)
03-30 09:34:25.741 E/AndroidRuntime( 2509): at android.app.ActivityThread.deliverResults(ActivityThread.java:3387)
Here's the relevant function:
public String getRealPathFromURI(Uri contentUri) {
String column;
column = "";
if (fileType == "picture") {
column = MediaStore.Images.Media.DATA;
}
if (fileType == "video") {
column = MediaStore.Video.Media.DATA;
}
String[] proj = { column };
Cursor cursor = managedQuery(contentUri, proj, null, null, null); // here lies the exception!
int column_index = cursor.getColumnIndex( column );
if (column_index == -1) {
alert("Path missing", "Could not locate the file requested", this);
return "";
}
cursor.moveToFirst();
return cursor.getString(column_index);
}
Here's sanitized relevant code (just removed client info)
/*
* Call the camera activity for video or picture
*/
protected void startCaptureIntent(String actionCode, int requestCode, int media) {
Intent i = new Intent(actionCode);
if (media == MEDIA_VIDEO) {
i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
}
startActivityForResult(i, requestCode);
}
/*
* Handle the activity result
*
* #see android.app.Activity#onActivityResult(int, int,
* android.content.Intent)
*/
#Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
//super.onActivityResult(requestCode, resultCode, intent);
Log.d("MYDEBUGGING", "Handling activity result. requestCode:" + requestCode + " resultCode:" + resultCode);
if (resultCode == Activity.RESULT_CANCELED) {
pic_upload_button.setEnabled(true);
video_upload_button.setEnabled(true);
fileType = "none";
showToast(this, "Request canceled, Touch the picture or image button to try again");
return;
}
switch (requestCode) {
case CAMERA_PIC_REQUEST:
switch (resultCode) {
case Activity.RESULT_OK:
postType = requestCode;
fileType = "picture";
// Seems that this is the only way to be sure I end up with an actual file.
filePath = getRealPathFromURI(intent.getData());
if (filePath != null) {
showToast(this, "Image ready to be shared");
} else {
showToast(this, "Something went wrong. Image could not be captured.");
}
break;
default:
alert("Activity failed", "Could not create picture file", this);
}
break;
case CAMERA_VID_REQUEST:
switch (resultCode) {
case Activity.RESULT_OK:
postType = requestCode;
fileType = "video";
// Seems that this is the only way to be sure I end up with a video file.
filePath = getRealPathFromURI(intent.getData());
if (filePath != null) {
showToast(this, "Video ready to be shared");
} else {
showToast(this, "Something went wrong. Video could not be captured.");
}
break;
default:
alert("Activity failed", "Could not create video file", this);
}
break;
}
}
fileType and postType are global to the class and are used to indicate to the http uploader what type of file to send. actionCode is either MediaStore.ACTION_VIDEO_CAPTURE or MediaStore.ACTION_IMAGE_CAPTURE depending on user selection.
Any thoughts?
My guess is that the contentUri or filetype values aren't correct, so the managedQuery call fails.