Android Studio: Does not show all errors immediately - android

I'm coming from Eclipse and I am used to immediate error reporting over the whole project.
Lets say I have this function:
public void test() {
//Do something
}
and I change it to
public void test(String someString) {
//Do something
}
Then eclipse would immediately highlight all classes in the project explorer, that call test() without also passing a string.
Android studio does not. It only shows it, when I happen to open such a file. Ofcource, when I compile, I will also get an error, but also only for the first file he tried to compile and failed and not for all.
I am currently in a big refactoring and this is really tedious. Compile - wait - fix one file - start over...
Am I missing someting? Not even Analyze/Inspect code... does the trick.
PS: I'm using Android Studio 2.2.3 with latest updates (24.02.2017)

Too late for you by now, but for future reference to yourself:
Instead of changing the signature of the method by adding an argument to it "manually", right click on the method, go to Refactor, go to Change Signature, in the Parameters tab click on the plus icon and add the parameter there. Now right click on the method again and select Find Usages. That will show you where you're calling the new refactored method and you can fix your code quickly.
However, to answer your question, you can see where all your errors are. Just go to Build and rebuild your project via Rebuild Project and then go the left hand side of Android Studio and change the project view to Problems
See if that helps

Related

'this#ActivityName' is not captured error Android/Kotlin

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.

Annotations in Application class are red, but everything is working, is it normal?

I opened the file Application.java, then on the top appeared dialog like you need to update something(I have not read properly and clicked authomatically), then every single annotation turned red denoting errorScreenshot from IDE. It seems like my app is working properly,should I leave my Application.java class in rest?
It can happen when your Android Studio loses sync with the generated code by annotations. Sometimes using gradle sync solves the issue, and in case it doesn't, try going the menu File -> Invalidate Caches/Restart

Module interface not updated

I have a library which I use in several projects.
In this library I have a function like:
public boolean update(Context context, String name,
UpdateResponseCallback callback)
throws firstException {
Now I want to change this firstException to secondException (or to the general Exception or whatever). The build of the library works okay. And also the generated files appears to be okay.
When I move to the App which includes this library things go wrong.
The compiler does not recognise the new/updated format. Also the quick help (mouse over) give the old interface.
I have already performed CLEAN and also File:InvalideChache but nothing helps.

Android Studio not recognizing Espresso/Hamcrest static method names without prefacing with the classname

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!

Eclipse Indigo does not allow #Override for non Activity overwritten methods

I am using Eclipse Indigo for Android development. The problem i face is that it does not allow #Override for non Activity overwritten methods. For example if i implement onErrorListner of MediaPlayer and i set attribute #Override with it then it gives the following compile time error:
The method onError(MediaPlayer, int, int) of type MyActivity must override a superclass method
And to fix this problem, i am suggested the following
Remove "#Override" annotation
Tough removing the #Override fixes the issue but why does it complain about it and also removing it may cause stopping some functionality of its parent etc??
I have downloaded many examples which use this "#Override" attribute with non-activity methods which proves that this is used and i might be missing some obvious thing. But i cannot run these examples in Eclipse Indigo without removing these "#Override" attributes from all the classes.
Why?
Any help is greatly appreciated.
Your project Java compiler level is set to 1.5 instead of 1.6. See here.
It is not good to remove that line. you need to change to JDK version in your eclipse then you will not get such errors. Follow, following steps for it,
Right Click on your Project & select Properties.
Then from the left section Select Java Compiler & select the Version of the JDK you installed. If it is already selected then de-select it & try it.

Categories

Resources