I've got this strange stack trace from Flurry Analytics and I have no idea where it comes from. All the classes are from android system and not a single line that tells me where it comes from.
This error happened 3 times on a same device with android 4.4.4
Any ideas? Thanks.
java.lang.RuntimeException
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2836)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2865)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2291)
android.app.ActivityThread.access$800(ActivityThread.java:144)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:212)
android.app.ActivityThread.main(ActivityThread.java:5135)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
dalvik.system.NativeStart.main(Native Method)
Caused by: android.app.ActivityThread.deliverResults(ActivityThread.java:3455)
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2823)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2865)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2291)
android.app.ActivityThread.access$800(ActivityThread.java:144)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:212)
android.app.ActivityThread.main(ActivityThread.java:5135)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:515)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
dalvik.system.NativeStart.main(Native Method)
Part of the problem here seems to be that Flurry error reporting is leaving out important information.
Anyhow, this is where I think the exception is coming from:
private void deliverResults(ActivityClientRecord r, List<ResultInfo> results) {
final int N = results.size();
for (int i=0; i<N; i++) {
ResultInfo ri = results.get(i);
try {
if (ri.mData != null) {
ri.mData.setExtrasClassLoader(r.activity.getClassLoader());
}
if (DEBUG_RESULTS) Slog.v(TAG,
"Delivering result to activity " + r + " : " + ri);
r.activity.dispatchActivityResult(ri.mResultWho,
ri.mRequestCode, ri.mResultCode, ri.mData);
} catch (Exception e) {
if (!mInstrumentation.onException(r.activity, e)) {
throw new RuntimeException(
"Failure delivering result " + ri + " to activity "
+ r.intent.getComponent().toShortString()
+ ": " + e.toString(), e);
}
}
}
}
(This code isn't from Android 4.4.4, but this particular method is identical in the versions I looked at ...)
It would seem that deliverResults is catching some exception it got further up the stack, and wrapping / resthoring it as a RuntimeException. At the point that the exception is constructed, it has a message, and cause. Whatever is generating the stacktrace has removed that information, and that is going to make diagnosis hard.
Related
code :
public void extractPhoneNumber(String input){
Iterator<PhoneNumberMatch> existsPhone= PhoneNumberUtil.getInstance().findNumbers(input, "IN").iterator();
while (existsPhone.hasNext()){
System.out.println("Phone == " + existsPhone.next().number());
Log.d("existsPhone",":"+existsPhone.next().rawString());
gotPhone.setText(existsPhone.next().rawString());
}
}
Log :
2019-06-11 16:23:43.059 11176-11176/com.example.cardscaning E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.cardscaning, PID: 11176
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cardscaning/com.example.cardscaning.Activity.ProcessImage}: java.util.NoSuchElementException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2678)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.util.NoSuchElementException
at com.google.i18n.phonenumbers.PhoneNumberMatcher.next(PhoneNumberMatcher.java:710)
at com.google.i18n.phonenumbers.PhoneNumberMatcher.next(PhoneNumberMatcher.java:43)
at com.example.cardscaning.Activity.ProcessImage.extractPhoneNumber(ProcessImage.java:291)
at com.example.cardscaning.Activity.ProcessImage.onCreate(ProcessImage.java:97)
at android.app.Activity.performCreate(Activity.java:6687)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2631)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2743)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1490)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Inside log I can get desire result but exception occurs when I am adding this line gotPhone.setText(existsPhone.next().rawString())
Desirable outcome is able use extracted number.
You are calling next() thrice in one iteration forcing the Iterator to move to an element that doesn't exist.
Instead of:
while (existsPhone.hasNext()){
System.out.println("Phone == " + existsPhone.next().number());
Log.d("existsPhone",":"+existsPhone.next().rawString());
//...
}
Use something like:
while (existsPhone.hasNext()){
PhoneNumberMatch phone = existsPhone.next();
System.out.println("Phone == " + phone.number());
Log.d("existsPhone",":"+phone.rawString());
//....
}
Yesterday from Crashlytics I noticed disk I/O error (code 522) while opening the database. Problem is that this crashed already has been reported from 16 users 36 times. Sadly I can't reproduce this error. Here's the code fragment where error occurs
SessionDbManager(Context context, String tripDbFileName) {
this.context = context;
this.tripDbFileName = tripDbFileName;
this.tripDbHelper = new SessionDbHelper(this.context, tripDbFileName);
SQLiteDatabase database = null;
int attempt = 1;
while (database == null) {
try {
database = this.tripDbHelper.getWritableDatabase(); // here's the error
} catch (android.database.sqlite.SQLiteException e) {
Crashlytics.logException(e);
XLog.e("Failed to load history data from database ", e);
if (attempt == 5) throw e;
}
attempt++;
}
db = database;
}
And here's the stack trace
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 522): , while compiling: PRAGMA journal_mode
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:932)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:677)
at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:363)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:337)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:251)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:737)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at eu.fishingapp.data.sql.session.SessionDbManager.(SourceFile:51)
at eu.fishingapp.data.sql.session.SessionContentProvider.update(SourceFile:753)
at android.content.ContentProvider$Transport.update(ContentProvider.java:384)
at android.content.ContentResolver.update(ContentResolver.java:1412)
at eu.fishingapp.data.sql.session.SessionDbHelper.renameSessionDb(SourceFile:584)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadFile(SourceFile:462)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadSessions(SourceFile:221)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadSessionsFiles(SourceFile:243)
at eu.fishingapp.data.network.synchronization.FileSyncIntentService.onHandleIntent(SourceFile:116)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:67)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
I have read about I/O error and found two possible answers I was thinking that this is because users ran out of free space on their devices. But here's some images from two app users
So this is definitely not storage issue :( Any ideas how to solve this problem?
EDIT: targetSdk version 22
This question already has an answer here:
java.lang.NumberFormatException: Invalid float: "x" in android
(1 answer)
Closed 5 years ago.
At first I am new in android development. I tried to make this small app where I wanted to take inputs from the users and show them to a (default)list view. When I put values in all the fields it works fine except when I keep the CGPA field empty it stopped. Unfortunately, MyApp is stopped
Here is the OnClickListener login button.
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
setData();
}
});
Here is the lines of setData() method where i guess the problem has occurred.
My question is "Is it a right approach to parse data?"
Float cgpa = Float.parseFloat(editTextCgpa.getText().toString());
if(cgpa<=4.00 && cgpa > 0.00 ){
student.setCgpa(cgpa);
}
else{
error = true;
editTextCgpa.setError("CGPA must be within 4 in scale");
}
Android Monitor:
Here is the error message that i found in android monitor.
11-25 13:06:18.917 7896-7896/com.ariful.lict.lictpractice E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NumberFormatException: Invalid float: ""
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseFloat(StringToReal.java:289)
at java.lang.Float.parseFloat(Float.java:300)
at com.ariful.lict.lictpractice.MainActivity.setData(MainActivity.java:55)
at com.ariful.lict.lictpractice.MainActivity$1.onClick(MainActivity.java:45)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
here does the convertion of the String to Float is causing the error ??
Is there anyone who can help me?
You are passing an empty string to be parsed...
Just change your code to check for null/empty String.
if(!editTextCgpa.getText().toString().isEmpty()){
Float cgpa = Float.parseFloat(editTextCgpa.getText().toString());
if(cgpa<=4.00 && cgpa > 0.00 ){
student.setCgpa(cgpa);
}
else{
error = true;
editTextCgpa.setError("CGPA must be within 4 in scale");
}
}
I am using metadata-extractor library, to read exif-data from photos in phone.
https://github.com/drewnoakes/metadata-extractor
I wanna get the GPS and some specific tags from metadata, for example:Latitude & Longtitude, focal length. I write code as below:
...
Metadata metadata = ImageMetadataReader.readMetadata(file);
String metaDataString = "" ;
GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
metaDataString += "Long: " + String.valueOf(gpsDirectory.getGeoLocation().getLongitude()) + "Lat: " + String.valueOf(gpsDirectory.getGeoLocation().getLatitude());
ExifSubIFDDirectory exifSubIFDDirectory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
metaDataString += "[focal length]" + exifSubIFDDirectory.getString(ExifSubIFDDirectory.TAG_FOCAL_LENGTH);
...
I received the NullException with code above. Please help me to figure it out. Thanks in advance.
** Add a log **
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NullPointerException
at com.testing.MetaData.LoadPhoto.doInBackground(LoadPhoto.java:113)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
The NPE error at code line 113 is
metaDataString += "Long: " + String.valueOf(gpsDirectory.getGeoLocation().getLongitude()) + "Lat: " + String.valueOf(gpsDirectory.getGeoLocation().getLatitude());
Cheers guys, you're all right. After debug, I saw some of my photos don't have GPS, and null.
I post the code to control null value as below (this can be also applied for other specific tag)
// Check if metadata contains the specific Directory
if (metadata.containsDirectoryOfType(GpsDirectory.class)) {
GpsDirectory gpsDirectory = metadata.getFirstDirectoryOfType(GpsDirectory.class);
//Check if Directory contains the specific Tag
if(gpsDirectory.containsTag(GpsDirectory.TAG_LATITUDE)&& gpsDirectory.containsTag(GpsDirectory.TAG_LONGITUDE)) {
metaDataString = "[Longtitude]: " + String.valueOf(gpsDirectory.getGeoLocation().getLongitude()) + ", " +
"[Latitude]: " + String.valueOf(gpsDirectory.getGeoLocation().getLatitude()) + ", ";
}
else {
//Show error or notification
}
}
That's it, any concern or better implement, please leave comment.
If your image does not contain GPS data, the returned directory will be null. Be sure to use a null check. Test again with an image that definitely contains GPS data.
I am generating a statistical calculator application.
So I want to format input from edittext like this
i/p = 3.5.6, 6.5 to 3.5 , 6.5
Using " , " (comma) as separator so splitting the input string to float array when a " , " occurs.
I want to ignore 3.5[.6] and generate array like this
s[1] = 3.5 , s[2] = 6.5
While calculating mean application crashes due to extra " . " dots.
s = it.getText().toString(); //"it" is edittext
s=s.replaceAll( ",+" , "," );
String[] strarray =s.split(",");
float[] farray = new float[strarray.length];
for(int i = 0; i < strarray.length; i++)
{
farray[i] = Float.parseFloat(strarray[i]);
}
--DEBUG LOGCAT--
W/dalvikvm(3051): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
FATAL EXCEPTION: main
java.lang.NumberFormatException: Invalid float: "6.7."
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseFloat(StringToReal.java:310)
at java.lang.Float.parseFloat(Float.java:300)
at com.cal.mc2.Mean$1.onClick(Mean.java:67)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)`
`at android.os.Handler.dispatchMessage(Handler.java:92)
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)
Force finishing activity com.cal.mc2/.Mean
How about this simple function (IdeOne link here: https://ideone.com/utKPjP):
public static float myParseFloat(String str) {
int firstDot = str.indexOf('.');
if (firstDot != -1) {
int secondDot = str.indexOf('.', firstDot+1);
return Float.parseFloat(secondDot == -1 ? str : str.substring(0,secondDot));
}
return Float.parseFloat(str);
}
Then you just replace this statement in your code:
farray[i] = Float.parseFloat(strarray[i]);
with:
farray[i] = myParseFloat(strarray[i]);
You can use regex like this :
public static void main(String[] args) {
String s = "3.5.6, 6.5";
s = s.replaceAll("(?<=\\d\\.\\d)\\.\\d", "");// positive look behind. Only replace `.[digit]` if it is preceeded by [digit][.][digit]
System.out.println(s);
String[] arr = s.split(",");
System.out.println(Arrays.toString(arr));
}
O/P :
3.5, 6.5 --> value of s after replacement
[3.5, 6.5] --> array contents