I'm repairing my friend's code and got confused.
My friend wants to fetch entered text (in EditText). Seems easy, right? Well, it is but instead of user input, he gets this warning/error:
To be honest I'm not sure how to fix it. He is coding in Kotlin (Android 10).
Activity that contains EditText:
And XML:
This is how it looks when debugging:
The app started working just fine after running "File -> invalidate Cashes/Restart" option, I just don't understand where this warning came from and how to fix it because the error remained unchanged (even though the app works). Do you have an idea how to solve it?
All the best!
fyi lambda expression like setOnClickListener from kotlin is not debuggable, see here.
if you want to debug variables inside setOnClickListener you should use the normal one e.g. setOnClickListener(object: View.OnClickListener {..})
sometimes there will be problem in auto generated binding files, if so it will be solved after invalidate cache and restart ide. sometimes the warning/error show but the project and complied without errors. so no need to worry about that. for next time post the code as code not screen shots.
I understand that the question is regarding evaluating expression, but there is a way you can read variables from your debugger console, even if you're inside an anonymous callback. I found it helpful sometimes. Here are the steps:
First enter debugger mode inside of your anonymous callback,
In your debugger console, look at the right side for "Frames"
Within Frames under , you'll see stack of function execution first top one on the list is the latest:
Click on row(s) below the latest function, until you find an instance of your activity AddInformationActivity. You will see the activity instance on the right side window under Variables. Don't go as far as selecting functions browned out, because those are from internal libraries.
When you see you AddInformationActivity instance, you can expand it and see its variables.
Hope that helps!
It's not a beautiful way, but if you create a method like this:
private fun debug() {
println()
}
and add a breakpoint on the println() it'll capture the activity.
(Don't use TODO as it'll crash the app with a NotImplementedError once called.)
I have this method now in my code all the time to call it whenever I need it.
I know, that question is old, but I just stumbled over it and needed a way.
Related
I am developing an Android app (It doesn't matter though) using RxJava2, and in some singleton there are some PublishProcessors.
And there are a lot of .onNext() calls on these PublishProcessors all over the project.
Now in order to debug, I need to know, on every .onNext() called, which line in my project invoked this .onNext().
Is there a way in RxJava(2) that I can achieve this?
I think you can use Frames tab in Debug menu.
For example, in this case, MainActivity line 18 trigger onNext
Ah, thanks to #PhanVanLinh, I found a solution that worked for me.
(Actually it has pretty much nothing to do with RxJava...)
You just need to print the stacktrace using Thread.currentThread.stackTrace and print it to your own string inside doOnNext(), but remember to do it before .observeOn() so that the thread won't switch, it must stay at the original thread that called .onNext(), otherwise you won't get meaningful information.
Then you will know which line that called .onNext().
I've developed an xposed module for whatsapp.
http://forum.xda-developers.com/xposed/modules/mod-whatsapp-extensions-add-extra-t3452784
I wanted to add feature to hide our own last seen still see others or report a fake last seen for eg: 1 Jan 1970.
I made following assumptions:
To do that first I hooked date and System.currentTimeInMillis methods to make whatsapp think its 1 Jan 1970. That worked but still last seen was shown perfectly.
Assumption: The last seen time value is directly taken from the server
Then I looked in the source to find where last_seen preference is referenced. Turns out it is only referenced in SettingsPrivacy activity's class.
Assumption: To hide our last seen and still see others we need to change last seen preference to 'visible to all' and turn that back to off once we get the last seen.
but the problem is it uses onPreferenceChangeListener. We cannot hook a method from the interface directly.
I cannot find the subclass which implements onPreferenceChangeListener as the classes shown in code are synthetic.
Please if anyone can help me with this, it will be great. I need to find which is preferencechangelistener for that preference. Rest I will manage.
This is kind of a brute force trick to get the implementation but I guess you can hook the app ClassLoader.loadClass and for each loaded class check if it implements the interface. If so hook its onPreferenceChangeListener.
I found a way to do it and its working.
http://forum.xda-developers.com/xposed/modules/mod-whatsapp-extensions-add-extra-t3452784
The way to do it is by hooking a method which takes a preference as argument. We create a preference ( com.whatsapp.preference.WAprivacy preference to be precise ) and then pass this preference with last seen set to desired value to the method. And we are done.
It is working so far.
I need to update several visual components in my app during a timeconsuming function, instead my app seems to hang during this function call, rather than update the visual components on the screen. When the function exit, I see only the last changes to the components.
Is there a simple way to do the updates, or do I need to create a parallel process and have a 'timer' to read the data simultaniously (using semaphores) and present them in the timer call ?
Any suggestions ?
I asked the same question yesterday here. Like mh taqia said you can use Application->ProcessMessages() but you have to be careful with it. For my application, it worked but look at some posts about the function first.
I tried following:
MainForm->Invalidate();
MyControlRoot->Repaint();
MyControlRoot is a control containing somewhat 50-60 different other controls
But MyControlRoot wouldn't repaint with this method. ..
Despite the warnings from you Remy, I tried Application->ProcessMessages();
...works for now...
By the way... I cannot see any warnings in Docwiki on using ProcessMessages... what could I expect?
RG
I wasn't sure exactly what headline to give this question because I'm not sure what this is technically called. In Android Studio while typing out Espresso tests I noticed that it refuses to accept something like this:
onView(withId(R.id.someId)).perform(click());
and instead will only accept this:
Espresso.onView(ViewMatchers.withId(R.id.someId)).perform(ViewActions.click());
even though every example that I've seen online shows the first example as correct code. Why is Android Studio forcing me to preface every ViewMatcher/Espresso/ViewActions/etc. method with the classname even after the imports are included in my class?
To clarify - trying to use the first example shows "cannot resolve method" and using autocomplete on it (which I have to do several times before it will work) invariably autocompletes to the second example. In all the "regular" code for my project autocomplete works correctly and short method names are recognized. I've tried doing a "clean" and "invalidate cache and restart" but no change.
Example of Google doc that shows usage according to the shortened code:
https://developer.android.com/training/testing/ui-testing/espresso-testing.html
You can try to check out your Android Studio Preferences for imports. Just go to Preferences -> Search "imports"
Here are the settings that I use and I don't have that issue:
What fixed the issue for me: just removed red withId in one place. Then just re-entered "withId": after that all the other red withId were replaced with black text color withId and now it compiled successfull!
I've had a search for this problem but nothing seems to help me to solve this particular error I am getting.
I am writing my first Android app and am coming across a java.lang.RuntimeException whenever I call SetContentView on a new activity.
There is nothing in the logcat which helps (an activity idle timeout is all because it falters on the call).
My activity Login has a layout set during OnCreate which works fine, but any subsequent calls fall over. Here's some code ;)
[Activity(Label = "Usage")]
public class Usage : TabActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//**FALLS OVER HERE**
SetContentView(Resource.Layout.Usage);
The Resource.Designer.cs has a record of my layout:
// aapt resource value: 0x7f030002
public const int Usage = 2130903042;
...and when I reference that layout by it's int value it falls back to the previous activity without hitting any breakpoints in the Usage activity.
Anyone got any thoughts or can point me in the direction of a similar post?
Legends!
UPDATE
I tried a whole stack of fixes I found on forums etc but nothing would fix this. I put the whole thing on the backburner while I worked on something else, came back to it and now it works...wish I could say what it was that made it work to help others out but I can't explain it! COULD have been an update to a new version of MonoDroid?
As stated in my comment to Stuart's answer, this problem appears to have resolved itself. I revisited the project all this time later and think that it might have just been a case of cleaning the project and rebuilding all. I have not had this problem since.
Sorry that this is not a detailed answer, I would suggest trying the ol' clean and rebuild.
I've recently had some issues when working in VS2010 where the resource ids are being not kept perfectly in-sync with the resource files and the java ids.
To resolve these, I generally find the quickest way is to add a new id to one of the layout xml files - this then causes a regeneration or the resources.cs file which then means the app works again.
If that doesn't help, then please post more info about what the message inside the RuntimeException is,
Although it's very late response, but someone who might be getting this sort of error. Wrap it with try-catch and it gives more details about the exception. I spent few hours before figuring out to do that