Find missing onError in the project - android

I am trying to locate a missing onError() in a project. It means that the app crashes because a subscription does not handle the throwables so I want to locate that subcription and add the onError method.
Unfortunatelly the stacktrace is not really helpful here and it only shows the line of the throw new IOException but nothing more:
FATAL EXCEPTION: main
Process: my.app.example.dev, PID: 20309
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:54)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)
at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.
            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)
            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)
            at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)
            at rx.internal.operators.NotificationLite.accept(NotificationLite.java:147)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:177)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.access$000(OperatorObserveOn.java:65)
            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:153)
            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:47)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
at com.splunk.mint.ExceptionHandler.uncaughtException(ExceptionHandler.java:42)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:58)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: retrofit.RetrofitError: java.io.IOException: No connectivity
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:385)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:221)
at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
at retrofit.RxSupport$2.run(RxSupport.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.io.IOException: No connectivity
at my.app.example.manager.ApiManager$NetworkAwareOKClient.execute(ApiManager.java:1071)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:322)
            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:221)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:271)
            at retrofit.RestAdapter$RestHandler$1.call(RestAdapter.java:269)
            at retrofit.RxSupport$2.run(RxSupport.java:46)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
            at java.lang.Thread.run(Thread.java:818)
Any ideas to locate the subscription (line in code) that does not have the onError() ?

This can be a pain to debug. Funnily enough I had an error inside the Action1<Throwable> [facepalm].
The best was to debug this is to register a global error handler. This will saw you the truth in your code:
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
#Override
public void handleError(Throwable e) {
Log.w("Error",e);
}
});
A discussion on github: https://github.com/ReactiveX/RxJava/issues/2293

If the onError is not implemented, then RxJava throw a OnErrorNotImplementedException exception. It's seems that RxJava didn't succed to call the onError method ("Error occurred when trying to propagate error to Observer.onError")
You can try to register an error handler to find the root exception.
static {
RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
#Override
public void handleError(Throwable e) {
e.printStackTrace();
}
});
}

Use this one:
RxJavaHooks.setOnError(throwable -> {
if (throwable != null && throwable.getMessage() != null) {
Log.e("Error", throwable.getMessage());
}
});
Instead of deprecated RxJavaPlugins.getInstance()

Related

Error when using setmarker() from an array to GPS map

I have an array of pictures which i extract the longitude and latitude details from using exif and put them on a marker on the GPS map. Currently i am using static array which i plan to change to a dynamic array in the near future. The current code crashes my app everytime i try to set my marker, i have no idea whats wrong.
public void setMarker() {
double latitude, longitude;
String[] filepath = {"/storage/emulated/0/Pictures/CapturyGallery/CapImage1451887532716.jpg", "/storage/emulated/0/Pictures/CapturyGallery/CapImage1452411474153.jpg"};
ExifInterface intf = null;
for (int y = 0; y < filepath.length; y++) {
try {
intf = new ExifInterface(filepath[y]);
} catch (IOException e) {
e.printStackTrace();
}
if (intf != null) {
latitude = Double.parseDouble(intf.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
longitude = Double.parseDouble(intf.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
LatLng latLngCurrent = new LatLng(latitude, longitude);
MarkerOptions options = new MarkerOptions()
.position(latLngCurrent)
.title("test");
mMap.addMarker(options);
}
}
}
LOGCAT
`
01-11 15:19:30.251 32226-32226/com.sp.fyp.captury E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.sp.fyp.captury, PID: 32226
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4298)
at android.view.View.performClick(View.java:5254)
at android.view.View$PerformClick.run(View.java:21179)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6843)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4293)
            at android.view.View.performClick(View.java:5254)
            at android.view.View$PerformClick.run(View.java:21179)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6843)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.NumberFormatException: Invalid double: "1/1,18/1,30/1"
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.initialParse(StringToReal.java:164)
at java.lang.StringToReal.parseDouble(StringToReal.java:282)
at java.lang.Double.parseDouble(Double.java:301)
at com.sp.fyp.captury.GPS.setMarker(GPS.java:181)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.view.View$1.onClick(View.java:4293)
            at android.view.View.performClick(View.java:5254)
            at android.view.View$PerformClick.run(View.java:21179)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:6843)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)`
According to the Standard Exif Tags (as defined in the Exif 2.3 standard)
The latitude/longitude is expressed as three RATIONAL values giving
the degrees, minutes, and seconds, respectively. When degrees, minutes
and seconds are expressed, the format is dd/1,mm/1,ss/1. When degrees
and minutes are used and, for example, fractions of minutes are given
up to two decimal places, the format is dd/1,mmmm/100,0/1
Thus, when you get the latitude and logitude from the ExifInterface, you are getting values like 1/1,18/1,30/1. Of course this String values cannot be converted to double using Double.parseDouble and throw a NumberFormatException.
You can take a look at How do I convert Exif long/lat to real values? to find a converter.

Error with reading parcelable object (after application is restored)

I have to save my custom class in save state bundle. So, I made it Parcelable and it looks good. When I rotate screen everything is goind well. But, when I minimalize my app, open some other, rotate screen and I try to go back to my app (from recent apps) it crashes.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.game/com.example.game.MainActivity}: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.game.Player)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.RuntimeException: Parcelable encountered ClassNotFoundException reading a Serializable object (name = com.example.game.Player)
at android.os.Parcel.readSerializable(Parcel.java:2378)
at android.os.Parcel.readValue(Parcel.java:2197)
at android.os.Parcel.readListInternal(Parcel.java:2520)
at android.os.Parcel.readList(Parcel.java:1655)
at com.example.game.Players.<init>(Players.java:106)
at com.example.game.Players$1.createFromParcel(Players.java:96)
at com.example.game.Players$1.createFromParcel(Players.java:93)
at android.os.Parcel.readParcelable(Parcel.java:2246)
at android.os.Parcel.readValue(Parcel.java:2146)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
at android.app.Activity.onCreate(Activity.java:949)
at com.example.game.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ClassNotFoundException: com.example.game.Player
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at android.os.Parcel$2.resolveClass(Parcel.java:2364)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
at android.os.Parcel.readSerializable(Parcel.java:2372)
            at android.os.Parcel.readValue(Parcel.java:2197)
            at android.os.Parcel.readListInternal(Parcel.java:2520)
            at android.os.Parcel.readList(Parcel.java:1655)
            at com.example.game.Players.<init>(Players.java:106)
            at com.example.game.Players$1.createFromParcel(Players.java:96)
            at com.example.game.Players$1.createFromParcel(Players.java:93)
            at android.os.Parcel.readParcelable(Parcel.java:2246)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
            at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
            at android.app.Activity.onCreate(Activity.java:949)
            at com.example.game.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.ClassNotFoundException: com.example.game.Player
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:308)
            at android.os.Parcel$2.resolveClass(Parcel.java:2364)
            at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1641)
            at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:657)
            at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1782)
            at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:761)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
            at android.os.Parcel.readSerializable(Parcel.java:2372)
            at android.os.Parcel.readValue(Parcel.java:2197)
            at android.os.Parcel.readListInternal(Parcel.java:2520)
at android.os.Parcel.readList(Parcel.java:1655)
            at com.example.game.Players.<init>(Players.java:106)
            at com.example.game.Players$1.createFromParcel(Players.java:96)
            at com.example.game.Players$1.createFromParcel(Players.java:93)
            at android.os.Parcel.readParcelable(Parcel.java:2246)
            at android.os.Parcel.readValue(Parcel.java:2146)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
            at android.os.BaseBundle.unparcel(BaseBundle.java:221)
            at android.os.Bundle.getSparseParcelableArray(Bundle.java:871)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:831)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1049)
            at android.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1864)
            at android.app.Activity.onCreate(Activity.java:949)
            at com.example.game.MainActivity.onCreate(MainActivity.java:24)
            at android.app.Activity.performCreate(Activity.java:6020)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2259)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2366)
            at android.app.ActivityThread.access$800(ActivityThread.java:149)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
So, players is parcelable class. It is basically a List. Player is another class, serializable.
Player.java
import java.io.Serializable;
public class Player implements Serializable{
private String name;
private int points = 0;
// getters and setters
}
Players.java
public class Players implements Parcelable {
private List<Player> players;
//constructor, getters, setters
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeList(players);
}
public static final Parcelable.Creator<Players> CREATOR = new Parcelable.Creator<Players>() {
public Players createFromParcel(Parcel in) {
return new Players(in);
}
public Players[] newArray(int size) {
return new Players[size];
}
};
public Players(Parcel in) {
in.readList(players, List.class.getClassLoader());
}
}
At this point I don't know why my app crash. When I rotate it it's ok, when I minimize and maximize is ok, when I minimize, do some staff (open another app, rotate screen etc) and try to maximize it from recents it crash.
I'll be very gratefull for any kind of help ;) !
Have a good afternoon!
Parcelable class nest parcelable objects only.
Here in your case Player is not parcelable and is used in Parcelable class Players. Try to implement Parcelable in Player class too.
Your problem with minimising and opening the application is because Parcelable object is saved but it is not retrieved properly.
try to make following changes in your code :
public class Player implements Parcelable{
String name;
int points;
// getter setter
public static final Creator<Player> CREATOR = new Parcelable.Creator<Player>() {
#Override
public Player createFromParcel(Parcel in) {
return new Player(in);
}
#Override
public Player[] newArray(int size) {
return new Player[size];
}
};
public Player(Parcel in) {
this.name = in.readString();
this.points = in.readInt();
}
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeInt(points);
}
}
And in Players class while reading the list replace:
in.readList(players, List.class.getClassLoader());
with :
players = new ArrayList<>();
in.readList(players, getClass().getClassLoader());
Your code should work fine after these changes.

Cloudmine java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;

I am trying to store some data using Cloudmine.
However, I got the error java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory; when I call initialize() for authorization.
I'm not running on a separate thread or something. I'm testing stuff out right now so I just have it so that when a button is clicked, it uploads some information from some EditText fields.
This is my code
public class ButtonClick implements View.OnClickListener {
private MainWindowActivity mainWindowActivity;
public ButtonClick(MainWindowActivity mainWindowActivity, Button doneBtn, Button addBtn) {
this.mainWindowActivity = mainWindowActivity;
addBtn.setEnabled(true);
addBtn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// This will initialize your credentials
// ERROR HERE
CMApiCredentials initialize = CMApiCredentials.initialize("id", "key");
SimpleCMObject location = new SimpleCMObject();
location.add("address", Runner.getAddressStr());
location.add("city", Runner.getCityStr());
location.add("state", Runner.getStateStr());
location.add("zip", Runner.getZipStr());
location.save(new ObjectModificationResponseCallback() {
public void onCompletion(ObjectModificationResponse response) {
Toast.makeText(mainWindowActivity, "Location saved: " + response.wasSuccess(), Toast.LENGTH_SHORT).show();
}
});
EditText address = (EditText) mainWindowActivity.findViewById(R.id.address);
address.setText("");
EditText city = (EditText) mainWindowActivity.findViewById(R.id.city);
city.setText("");
EditText state = (EditText) mainWindowActivity.findViewById(R.id.state);
state.setText("");
EditText zip = (EditText) mainWindowActivity.findViewById(R.id.zip);
zip.setText("");
}
}
This is the Logcat:
Process: prog, PID: 26580
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
at prog.ButtonClick.onClick(ButtonClick.java:52)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[zip file "/data/app/prog-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
            at com.cloudmine.api.CMApiCredentials.<clinit>(CMApiCredentials.java:21)
            at prog.ButtonClick.onClick(ButtonClick.java:52)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Suppressed: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 13 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
As I have commented, download zip file from SLF4J distribution and use as library in your project. Then, use slf4j-api-1.7.12.jar (and slf4j-android-1.7.12.jar if needed).
I had the same error and found this solution on github.
Just add the following to your grandle:
implementation 'org.slf4j:slf4j-api:1.7.25'
https://github.com/nomis/slf4j-android
I hade the same problem only on Android 5.0 - 5.1 (a real device and emulators). At that moment, I used Android Studio 2.3.3 and build tools v26.
I solved the problem turning off Instant Run that I didn't use anyway.
Steps:
go to File -> Settings -> Build, Execution, Deployment -> Instant run
Disable it (first checkbox).

AudioManager setStreamMute() Null Pointer Exception

I am getting Null Pointer Exception on line 219: amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);. It was not happening before, today i saw it first time, i am using Android 5.0. Code mutes notification sound when activity starts and unmutes when it is destroyed.
Code:
private AudioManager amanager;
#Override
protected void onCreate(Bundle savedInstanceState) {
amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
}
#Override
protected void onResume() {
super.onResume();
if(amanager!=null) {
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
}
}
#Override
protected void onPause() {
if(amanager!=null) {
amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
}
super.onPause();
}
Error:
java.lang.RuntimeException: Unable to resume activity {com.jemshit.itu/com.jemshit.nfcAttendance.ClassActivity}: java.lang.NullPointerException: Null pointer exception during instruction 'invoke-static {v0}, android.os.IBinder android.media.AudioService$VolumeStreamState$VolumeDeathHandler.access$5300(android.media.AudioService$VolumeStreamState$VolumeDeathHandler) // method#11492'
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3346)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3377)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2728)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Null pointer exception during instruction 'invoke-static {v0}, android.os.IBinder android.media.AudioService$VolumeStreamState$VolumeDeathHandler.access$5300(android.media.AudioService$VolumeStreamState$VolumeDeathHandler) // method#11492'
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1493)
at android.media.IAudioService$Stub$Proxy.setStreamMute(IAudioService.java:992)
at android.media.AudioManager.setStreamMute(AudioManager.java:1466)
at com.jemshit.nfcAttendance.ClassActivity.onResume(ClassActivity.java:219)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1255)
at android.app.Activity.performResume(Activity.java:6338)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3335)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3377)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2728)
            at android.app.ActivityThread.access$900(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5832)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
It's an Android bug it's not your code. Put a try/catch block in your code to avoid the crash.

Android - Activity transition crash with ActionBarActivity

I'm currently trying to implement Material Design activity transitions. For a reason i really don't know, it crashes. Can someone give me a clue? (I don't know if it's important, but inside my MainActivity, i've a ViewPager with Fragments from which I try to start the next Activity)
Thanks a lot for your help.
My code:
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {
(...)
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.i("TAAG", "MainActivity::onCreate1");
super.onCreate(savedInstanceState);
Log.i("TAAG", "MainActivity::onCreate2");
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Log.i("TAAG", "MainActivity::onCreate3");
setContentView(R.layout.activity_main);
Log.i("TAAG", "MainActivity::onCreate4");
(...)
}
Here are the logs:
11-13 18:12:36.442 1098-1098/I/TAAG﹕ MainActivity::onCreate1
11-13 18:12:36.544 1098-1098/I/TAAG﹕ MainActivity::onCreate2
11-13 18:12:36.559 1098-1098/E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: mypackage, PID: 1098
java.lang.RuntimeException: Unable to start activity ComponentInfo{mypackage/mypackage.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:301)
at mypackage.MainActivity.onCreate(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Try calling getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); before super.onCreate().

Categories

Resources