Android testfairy java.lang.VerifyError? - java

After I upload my apk to testfairy and install it I get a java.lang.VerifyError crash
The class extends android.support.v4.app.Fragment
This is the function that is crashing. It crashes on the function execution, not the click but when I remove the onClick. Inner stuff all works.
fitroom_lly is LinearLayout
mixpanel defined :
MixpanelAPI mixpanel = MixpanelAPI.getInstance(getActivity(), getResources().getString(R.string.Mix_Panel_Token));
Function:
private void AddOnFittingRoomClickListener() {
fitroom_lly.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mixpanel.track("Fitting room");
}
});
}
Error:
java.lang.VerifyError: co/slider/fashion/Slider/SliderFragment$6
at co.slider.fashion.Slider.SliderFragment.AddOnFittingRoomClickListener(SliderFragment.java:334)
at co.slider.fashion.Slider.SliderFragment.onCreateView(SliderFragment.java:135)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)

I work for TestFairy. I need a bit information, is your app multidex'd or a single dex? That's the only VerifyError we ever encountered, and we have an answer for that. Though I would need you to email support at testfairy.com, and one of the technical developer will explain to you the workaround. We're making this solution available to everybody, but in the meanwhile, only support is explaining this.

Related

Not Serializable SQLiteCursor when I go home

My app is a RSS adapter who works with SQlite, viewpagers and RecyclerViews. Everything works fine but once I leave my app pressing home button, my app crashes and shows the following logcat:
FATAL EXCEPTION: main
Process: com.herprogramacin.hermosaprogramacion, PID: 14900
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.herprogramacin.hermosaprogramacion.UI.Adapters.RVAdapter)
at android.os.Parcel.writeSerializable(Parcel.java:1468)
at android.os.Parcel.writeValue(Parcel.java:1416)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:711)
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:137)
at android.os.Parcel.writeTypedArray(Parcel.java:1254)
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:384)
at android.os.Parcel.writeParcelable(Parcel.java:1437)
at android.os.Parcel.writeValue(Parcel.java:1343)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
at android.os.Bundle.writeToParcel(Bundle.java:1079)
at android.os.Parcel.writeBundle(Parcel.java:711)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3701)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4622)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.io.NotSerializableException: android.database.sqlite.SQLiteCursor
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1463)
at android.os.Parcel.writeValue(Parcel.java:1416) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330) 
at android.os.Bundle.writeToParcel(Bundle.java:1079) 
at android.os.Parcel.writeBundle(Parcel.java:711) 
at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:137) 
at android.os.Parcel.writeTypedArray(Parcel.java:1254) 
at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:384) 
at android.os.Parcel.writeParcelable(Parcel.java:1437) 
at android.os.Parcel.writeValue(Parcel.java:1343) 
at android.os.Parcel.writeArrayMapInternal(Parcel.java:686) 
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330) 
at android.os.Bundle.writeToParcel(Bundle.java:1079) 
at android.os.Parcel.writeBundle(Parcel.java:711) 
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:3701) 
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4622) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 
Where we can read "Caused by: java.io.NotSerializableException:android.database.sqlite.SQLiteCursor"
Why Is it happening this?
EDIT 1:
How my app works.
Main activity gets the XML code for RSS and once it finishes, MainActivity get the cursor and generates the Recycler View Adapter.
Main activity creates the viewpager and sends to him the RecyclerView Adapter.
ViewPager creates a new fragment and passes the adapter to the new Fragment
The new fragment generates the view and sets the adapter with the data that ViewPager sent to him.
I realised that is crazy to generate the adapter in MainActivity and pass it to the fragment through 3 clases. Could be this the problem?
It sounds like you are holding a reference to a SQLiteCursor in an activity or other view logic. When Android is attempting to pause your activity it tries to serialize the data the activity currently has (and dependent objects) so that they can be deserialized when the activity resumes. Look around for how you are using SQLiteCursor, you should not be passing them around to your activity or any model objects used by your activity.

Error, Null Pointer Exception for SharedPreferences

So I keep getting the same error no matter how many times I try to tweak my code here and there. I will be posting every little bit of code that has to do with the error.
I will not include unnecessary code so if my code doesn't look complete it's because I cut it out to make it easier for people to diagnose the issue!
First Class
I wrote !!! error !!! after the code that was said to have been the cause of the error according to my log.
SharedPreferences sf;
SharedPreferences.Editor editor;
#Override
protected void onCreate(Bundle savedInstanceState) {
sf = getSharedPreferences("MyData", MODE_PRIVATE);
checkCookie();
}
//function for making sure there's data
public void checkCookie() {
editor = sf.edit();
if (sf.getInt("cookies", -1) == -1) {
editor.putInt("cookies", 0);
}
}
//function for retrieving amount of cookies
public int getCookies()
{
editor = sf.edit(); !!! Error here !!!
int x = sf.getInt("cookies", 0);
return x;
}
//function for changing amount of cookies
public void changeCookies(int x)
{
editor = sf.edit();
editor.putInt("cookies", x);
}
Second Class
I put !!! error !!! at the second error given which basically is what calls the function with the error in it.
//MyActivity is the first class
MyActivity mCookie = new MyActivity();
//function for adding cookies
public void cookieCalc(){
if (Math.abs((5-(millis/1000))) <= 0.005)
mCookie.changeCookies(100 * CB); ... much more similar code
//an if statement within a function which just calls the function getcookies and cookiecalc
if (loop == 2){
cookieCalc();
myText.setText("= " + mCookie.getCookies()); !!! this calls the function which gives error !!!
}
The error is 100% because of SharedPreferences as it worked with normal variables, but I needed to save the variables and was told this is a very easy method to do so. If all of this is still not enough and I cannot explain it to you I will then paste my entire code on gitHub or another viewing platform.
Error Logs
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke interface method 'android.content.SharedPreferences$Editor android.content.SharedPreferences.edit()' on a null object reference
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at app.z0nen.slidemenu.MyActivity.changeCookies(MyActivity.java:74)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at app.z0nen.slidemenu.menu1_Fragment.cookieCalc(menu1_Fragment.java:75)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at app.z0nen.slidemenu.menu1_Fragment$1.onClick(menu1_Fragment.java:148)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.view.View.performClick(View.java:5242)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.widget.TextView.performClick(TextView.java:10571)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:21196)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.os.Looper.loop(Looper.java:145)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6938)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
04-27 21:11:46.258 26975-26975/app.z0nen.menu E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
You should never create activity instance by yourself! Only system should do that.
If you create instance yourself, onCreate will never get called, as this instance won't go through standard activity lifecycle.
do not new instance by yourself. onCreate was br
Solved
SharedPreferences sf = this.getActivity().getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
because it was in a fragment class I had to add this.getActivity() and I also ended up adding Activity.MODE_PRIVATE. I probably was getting null pointer exception because it had no way to access my Activity class because fragments extend something else? Just a guess of mine, so far it is still not working how I want it to but I prevented crashes. edit it wasn't working because I didn't do editor.commit(); to save the changes.

NullPointerException in logcat with no clues

I am violating best practices here trying to figure this out, so to start off with, I realize that and I appreciate any insight. I'm making something simple that relies on a lot of Dialog calls. Nothing fancy, not calling a lot of Fragments. My game will require no permissions.
With the backstory out of the way, I'm getting this NPE:
06-13 01:29:03.581 24690-24690/com.myapp.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myapp.myapp, PID: 24690
java.lang.NullPointerException
at android.widget.FrameLayout.onMeasure(FrameLayout.java:309)
at android.view.View.measure(View.java:17388)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:17388)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5353)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2533)
at android.view.View.measure(View.java:17388)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2217)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1354)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1553)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1238)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6473)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
In my very flat app, I do this:
public static MainActivity ACTIVITY;
#Override
protected void onCreate(Bundle savedInstanceState) {
ACTIVITY = this;
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
ACTIVITY.setContentView(R.layout.activity_main);
Then I do a bunch of stuff that works fine. The problem is, I call a class that does a battle event:
FightEvent thisFight = new FightEvent(this);
ALLOWSAVE = false;
thisFight.doFightEvent();
In that class, when the fight starts, I do:
ACTIVITY.setContentView(R.layout.activity_fight);
When I exit the fight, I do:
ACTIVITY.setContentView(R.layout.activity_main);
PLOT TWIST: This all works fine in older versions. I'm trying to make my game 100% compatible back to API 8.
Works great in API 8. API 19-22, not so much.
Help?

Static dialog with TextView

what`s wrong with this because I cant compile to apk. Error is Cannot use this in a static context but if I change this to context app freeze when dialog must appear.
public static void mydialog(final Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
TextView myMsg = new TextView(this);
myMsg.setText("Central");
}
Logcat error:
android.view.WindowLeaked: Activity com.test.testapp.activities.MenuActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{430fc9a8 V.E..... R.....I. 0,0-1048,466} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:457)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:267)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:288)
at com.dialog.dialog.showDialog(RateThisApp.java:229)
at com.dialog.dialog.showDialogIfNeeded(RateThisApp.java:108)
at com.test.testapp.activities.MenuActivity.onCreate(MenuActivity.java:47)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
A static method is not associated with any particular instance of a class. It is a method associated with the class itself. Thus this has no meaning in a static method- there is no instance of the class to reference.
If this method is in a class that is a Context (e.g. an Application subclass or an Activity), then you can remove the static modifier and use this like you are already trying to do.

NullPointerException: SetOnClickListener(this) - Android

When running my application in Android Studio I get a NullPointerException at line 30 which is this:
llTheory.setOnClickListener(this);
which has always worked for me.. I am implementing View.OnClickListener and have the override method here:
#Override
public void onClick(View v) {
....
}
My LinearLayout is declared before the setOnClickListener here:
LinearLayout llTheory = (LinearLayout) findViewById(R.id.llTheory);
so what is going wrong? Here is my LogCat output:
10-20 21:09:24.045 14625-14625/com.timmo.applauncher E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.timmo.applauncher, PID: 14625
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.timmo.applauncher/com.timmo.timmoapplauncher.Main}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2224)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5153)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.timmo.timmoapplauncher.Main.Init(Main.java:30)
at com.timmo.timmoapplauncher.Main.onCreate(Main.java:78)
at android.app.Activity.performCreate(Activity.java:5312)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5153)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
            at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
            at dalvik.system.NativeStart.main(Native Method)
Fragments work a little bit differently.
You have to use the concept of rootview when dealing with them. Otherwise you will find yourself always coming across the dreaded "NULL POINTER" exception.
Here is how to go about it.
Define the rootview when you inflate each view for each fragment, then call the onClick functionality.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View rootview = inflater.inflate(R.layout.xml_you_want_to_inflate, container,false);
// Now call rootview and the onclick fuction, presumably for a list or button
rootview.findViewById(R.id.your_button/list_id_here).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do stuff.
}
});
Another alternative is using getView which always returns the rootview. Try this instead
LinearLayout llTheory = (LinearLayout) getView().findViewById(R.id.llTheory);
This link explains a similar problem.
The former way however is the correct way as you isolate your fragments from each other and understand the view hierarchy correctly. I would read this. Trust me the time investment reading that stuff is worthwhile then the hours you'll spend otherwise with half-wit hack job ideas to make stuff work.
findViewById returns a null value when the requested view cannot be found.
Check in your corresponding xml that a view is indeed declared with the id #id/llTheory
A standard Java best practice would be checking a casted item before using it.
Do you have
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_with_R_id_llTheory);
...
in your activity? Your activity (or fragment hosted by activity) must have layout with R.id.llTheory.

Categories