Ok, I have some fictional class
public class TEMP {
String data;
View.OnClickListener onClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
if (data != null) {
}
}
};
}
And it looks like this in Android Studio:
If I collapse all - it looks ugly:
If I remove that if block inside onClick() - it looks good:
Why is this happening and how can I solve this issue?
It's been a while, so I'm not sure how helpful this is.
This is folding the function into a lambda-like visual structure with Java 8 lambda-notation. Single method interfaces are (almost) equivalent to lambdas in Java 8. Android Studio currently does NOT support Java 8 lambda notation (details found at the bottom of this answer: Is it possible to use Java 8 for Android development?).
A workaround IS available for Java 8, based on the Jack toolchain. Here is the the workaround, and here is the deprecation of the Jack toolchain.
Another note is that according to here and here, Android Studio 2.4 preview 4 and later appears to support actual lambda notation. Note that these are previews, and the latest official version is 2.3.2.
As for how to fix it, I don't believe it is possible. You may be able to use the region feature to duplicate what you are trying to achieve. The link above is a how-to sort of thing.
Related
The problem:
#Nullable
private View view;
public doSomethingWithView() {
checkNotNull(view); //<- this throws NPE if parameter is null
view.showWarningAboutIssue(); //<- IDE reports about possible null here
}
Is there a way to configure the IDE, so that it doesn't report for a possible NPE on the second line?
UPDATE:
I'm using Dagger checkNotNull method which is identical to Guava ones. If I change import from Dagger to Guava my IDE removes the warning.
UPDATE #2
With latest update of Android studio I can not reproduce it anymore
You need to add the following comment before view.showWarningAboutIssue() statement:
//noinspection ConstantConditions
This can also be performed by the GUI : Alt+Enter (or "bubblelight" menu), then choose Assert view!=null and then Suppress for statement:
When running unitTest on AndroidStudio (1.4), my below test fail as per title i.e. java.lang.NoSuchMethodError: org.assertj.core.api.Assertions.assertThat(Ljava/util/Map;)Lorg/assertj/core/api/MapAssert;
#Test
public void mapTest() {
Map<String, String> map = new HashMap<>();
map.put("Key1", "Value1");
map.put("Key2", "Value2");
Assertions.assertThat(map).isNotNull();
}
When I run it from command line using gradlew command, it passed. I'm already pointing my Java to jdk1.8.0_66.jdk. Anyone knows why?
(p/s: I get the latest AndroidStudio 2.0 Preview 5, my test fails massively. So I decided to stay with the older version of Android Studio).
Trying to search for help and found this link https://github.com/joel-costigliola/assertj-core/issues/395. Apparently he also face the same issue on IDE. Any clue what's the cause?
I would double check the classpath.
Use assertj core 1.7.1 - it's a version depending on java 6 whcih I'm sure is Android compatible.
Hope it helps
i have a pojo class
run this code
Field[] fields = clazz.getDeclaredFields();
i got a field under Android Studio IDE :
its type is interface com.android.tools.fd.runtime.IncrementalChange
its name is $change
My Android Studio version is 2.0 Preview 4
the pojo class which i definded by myself didn't have $change field
when i run the code in eclipse, it works normal.
where did the field come from?
how can i avoid this field , is there some setting in Android Studio ?
Instead of turning off instant run we can resolve this issue by utilising synthetic modifier check. 'com.android.tools.fd.runtime.IncrementalChange' is synthetic so we can check whether the field is synthetic using isSynthetc method.
Field[] fields = objClass.getFields();
for (Field field : fields) {
String name = field.getName();
Object value;
if(field.isSynthetic()){
continue;
}
//add your code here
}
Most likely this field is added in order to support the Instant Run feature added in Android Studio 2.0, and will not appear if you turn off Instant Run.
I think diordna answer is best link。install run is Android Studio new function,I won't close it。
I use JsonTool link in my sdk library ,when I run my app with androidStudio2.2 JsonTooll.objectToJson() give me a bad json String ,I add code
if (name.contains("this$") || field.isSynthetic()) continue;
solve it
I have eclipse 3.7 indigo; I installed gwt plugin and its designer; The problem is (time after time) when I add new widget X to composite the
palette (keeps widget selected)
components (doesn't show the new widget in the tree)
properties (doesn't show the new widget properties)
...so I cannot select another widget unless I resize the whole eclipse application to force its GUI repaint :(
It seems like palette and other managers don't get report "widget was added from windowbuilder" or similar :(
Moreover, I cannot edit widget's text if I have input method as "System" which is the default on btw so the only one input method which works is "X Input Method" but anyways it doesn't solve the mentioned focus regain problem;
That makes eclipse indigo really hard to use; So my question is... how to fix that?
p.s.
eclipse 3.7 (indigo)
gwt plugin - https://dl.google.com/eclipse/plugin/archive/3.6.0/3.7
gwt designer - http://dl.google.com/eclipse/inst/d2gwt/latest/3.7
gwt sdk 2.2
jdk 1.7
jre 1.7
OS Linux x64
Thanks
I had to do my own research concerning the issue; I noticed there is some kind of "jobs order conflict" or similar with the default constructor based code style as :
public class MyTestUI extends Composite {
private FlowPanel flowPanel;
public MyTestUI() {
flowPanel = new FlowPanel();
initWidget(flowPanel);
}
}
...so, as a workaround, I had to play with code generator as;
window -> preferences -> windowbuilder -> gwt
(combobox) method name for new statements : initComponents
variable generation : field
statement generation : flat
just to avoid having in-constructor init as a result I have code generated as :
public class MyTestUI extends Composite {
private FlowPanel flowPanel;
public MyTestUI() {
initComponents();
}
private void initComponents() {
flowPanel = new FlowPanel();
initWidget(flowPanel);
}
}
...btw there is a problem with focus regain if input method is "System" and initComponents() method generated first time; so before starting adding widgets I had to select "X input method" to avoid synch-ed jobs; So "X input method" needs to be the default one, as I can get it :)
EDIT :
The effect I faced very looks like bug 388170; So I tried to modify eclipse.ini argument as
-Djava.awt.headless=true
It seems like the headless helps a bit but anyways eclipse sometimes does hang when using windowbuilder especially DnD :P
Anyways I want to point I faced the mentioned issue first time cause similar windows x32 eclipse indigo version works pretty fine with gwt;
p.s.
The solution is not final (the hang problem still occurs on DnD evens) and I am still looking for a more optimal one; So do comment if you have some helpful tips or ideas;
With a skeleton project with FirstView from HotTuna package, and with Build linker behavior set to "Link all assemblies", I get the following error:
System.MissingMethodException: Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector
Using NuGet package v3.1.1 for all MvvmCross (4 packages)
LinkerPleaseInclude file does have the line
[MonoTouch.Foundation.Preserve(AllMembers = true)]
Using the latest stable build:
On PC:
Xamarin for VS 1.12.278
Xamarin.iOS 1.12.278
Mac:
Xamarin.iOS 7.2.2.2
Of course with Linker behavior of SDK only, it runs fine. Any suggestions anyone?
Solved; So, with the basic project, there were three consecutive errors in the following order:
System.MissingMethodException: Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector
can be resolved either by --linkskip=Cirrious.Core (ugly), or by including the following in LinkerPleaseInclude.cs
public void Include(MvxPropertyInjector injector){
injector = new MvxPropertyInjector ();
}
Next error is:
Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialize ViewModel for type {0} from locator MvxDefaultViewModelLocator - check MvxTrace for more information
This one is difficult; Simple fix is to ofcourse to do a --linkskip=portableLibrary, or to crate an instance of the ViewModel somewhere (perhaps in LinkerPleaseInclude.cs); problem with the second approach at-least in my case is, most of my VM doesn't have a parameter less constructor, and obviously using IOC in this case wouldn't help.
Final Error:
System.ArgumentNullException: missing source event info in MvxWeakEventSubscription
Parameter name: sourceEventInfo
Either use --linkskip=System (ugly), or add the following to LinkerPleaseInclude.cs
public void Include(INotifyPropertyChanged changed)
{
changed.PropertyChanged += (sender, e) => {
var test = e.PropertyName;
};
}
This was enough for my basic project to run with LinkAllAssemblies, Using LLVM optimizer, and Use SGen collector.
Hope this will help anyone looking for a solution.
I hit this when my XCode was out of sync with the latest Xamarin on my Mac. Upgrading XCode to the latest resolved the problem.