I'm an Android dev who is using AndroidStudio or IntelliJ IDEA.
I tend to trust my IDE and I'm annoyed with next facts:
In android project when IDE autogenerates a method in java that extends Kotlin class then both IDE uses #NotNull instead of #NonNull, is there setting for this? This
We have #ParametersAreNonnullByDefault but when I override the method from the point 1 and I don't put any annotation IDE warns me, but why?
Am I wrong in my assumptions?
Are there solutions?
Which annotations to use for null/not-null is set under Configure annotations... in the Compiler page of the Settings/Preferences dialog. Select the one you want and press the checkmark button. See https://www.jetbrains.com/help/idea/nullable-notnull-configuration-dialog.html for documentation.
I can't test right now whether IDEA/AS use the default annotations from there when overriding a method which already uses another, but if they don't you'll need to file a ticket.
Related
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
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 have recently migrated to Android Studio and I am pretty used to the Source -> Override/Implement feature in Eclipse.
I was wondering where I could find the same feature on Android Studio. I've tried "Alt-Insert"/Generate-Override methods but I don't find the OnPause() method to override in the list. How do I get the methods that I want to override in the list?
These are the only methods that are available to me on my IDE.
Ctrl + O
should work well in Android Studio.
Press Alt(Left one)+insert.
It shows all the dialog with heading "Generate"
Choose override methods.
Shortcut- Ctrl+O
The method you want to override has to be declared in a class you implement or extend. It might be that your class does not extend Activity (for example). And your project might have to be an android project and not a plain java project.
My understanding is that you need to have the class in your code for Android Studio to offer you the override options pertaining to that class. The image you've posted seems to have only one class.
See how many I got:
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.
I'm making a paid/free version of my app so have a 'Library Project' that the two apps use.
I'm trying to use Android Annotations to clean up my code:
http://code.google.com/p/androidannotations/
Unfortunately when I use this in my shared library project, one of my projects gets the error in Eclipse:
The type xActivity_ is already defined xActivity_.java /ProjectName/.apt_generated/lib/activities/
Because Android Annotations automatically creates a new activity with an extra '_' in the folder .apt_generated one of the apps is allowed to create this file, but the other gets the error "already defined".
Is there a way in Eclipse to resolve this? Or is it a problem with the Android Annotations?
This seems to be an AndroidAnnotations bug, and should be reported on the dedicated bug tracker.
AndroidAnnotations wasn't designed with this use case in mind, but this is still a very valid use case. The problem seems to be that the activity is generated in the shared library project, when it should be generated in each depending project, am I right ?
(please answer in the bug tracker)
This question is quite old, but I thought that I should mention android annotations now supports being used in libaries:
https://github.com/excilys/androidannotations/wiki/Library-projects
One caveat is that due to the way android library projects generate the R class, you cannot reference resouces directly inside the annotations. Eg, you cant do this:
#EActivity(R.layout.myLayout)
public class MyActivity extends Activity {
#Click(R.id.myButton1, R.id.myButton2})
public void someButtonClicked() {
}
}
Instead you must do this:
#EActivity(resName="myLayout")
public class MyActivity extends Activity {
#Click(resName={"myButton1", "myButton2"})
public void someButtonClicked() {
}
}
I just knew AndroidAnnotations (which seems a great tool!) but I think that if you do this using different projects (sharing the same library) your problem should be solved.