Android Studio IDE Error Indication - android

I am relatively new to StackOverflow and Android Studio so apologies for newbie question!
I recently switched over to Android Studio from Eclipse.
I am noticing that when one function in one of my source files has an error that ALL functions in that file on the project view pane on the top left are showing the red squiggly so it is a little more time consuming to actually get to the error. Any ideas as to why this is happening?
Thank you

As Shlublu points out, it is difficult to say without an example. Here is one possible situation. Take this class:
public class MyClass {
private int myNumber;
public MyClass( int number) {
this.myNumber = number;
}
public int getAnswer() {
return this.myNumber;
}
private void someMethod() {
int x = 0;
} // remove this } and all below is an error
#Override
public String toString() {
return String.valueOf(this.myNumber);
}
#Override
public boolean equals(Object obj) {
return true;
}
}
Removing the } at the end of the someMethod() causes all methods below that to have an error.

Related

Mysterious annotations showing up on decompiled code after using Proguard

I just tested out proguard to obfuscate my android app.
But decompiling the apk shows that obfuscated functions have a weird annotation on top of them that displays the real function name, the real class name AND the real file name. How is that possible? Why is this happening?
The decompiled code looks like this,
#f(c = "com.my.app.package.Classname", f = "Classname.kt", l = {49, 51}, m = "RealFunctionName")
public static final class b extends i.b0.j.a.d {
public /* synthetic */ Object s;
public int t;
public final /* synthetic */ Classname u;
public Object v;
public Object w;
public Object x;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public b(Classname classname, i.b0.d dVar) {
super(dVar);
this.u = classname;
}
#Override // i.b0.j.a.a
public final Object l(Object obj) {
this.s = obj;
this.t |= Integer.MIN_VALUE;
return this.u.c(this);
}
}
This happens even if I remove ALL proguard rules to make it obfuscate everything without any exceptions. So where does this annotation come from? And why does it happen? Any help would be appreciated!

Using Android Plugin: Nonexistent function 'getPluginName' in base 'JNISingleton'

Godot version: 3.2.3
Issue description:
I am new at using Android Plugins in Godot, so I created this simple plugin with only one method.
public class GodotProva extends GodotPlugin
{
public GodotProva(Godot godot) {
super(godot);
}
#NonNull
#Override
public String getPluginName() {
return "mylibrary";
}
}
I tried to use it in Godot, with the following code:
func _pressed():
if Engine.has_singleton("mylibrary"):
var singleton = Engine.get_singleton("mylibrary")
print(singleton.getPluginName())
I created an apk and installed it on my Android device. The problem is that when I press the button (and the function _pressed() is called), I can see from the logcat the error Nonexistent function 'getPluginName' in base 'JNISingleton'
I am sure that the plugin is found, because the "singleton" variable is not null.
What am I doing wrong?
I found out that in Godot I can only call custom functions. The methods of the class GodotPlugin (such as getPluginName, getPluginMethods...) cannot be directly called.
In my case, I needed to define methods in getPluginMethods in my GodotPlugin like this:
public void firstMethod() {
// TODO
}
public void secondMethod() {
// TODO
}
#SuppressWarnings("deprecation")
#NonNull
#Override
public List<String> getPluginMethods() {
return Arrays.asList("firstMethod", "secondMethod");
}
I don't know why this case is not documented, but I wasted a lot of time on this and I think it would be useful for other people...

Android error during build - "default public constructor with no argument must be declared". What's the cause?

Android studio returned an error during build, even after running Clean, and rebuilding:
A default public constructor with no argument must be declared if a
custom constructor is declared.
I could not find a line number, nor a file referenced. I have no idea what causes this, as there's no indication from the build where or what the cause of this is.
If you have a custom constructor like this
public class Doge extends RealmObject {
public Doge(String name) {
...
Then you must also have a default constructor with no additional parameters.
public Doge() {
// default values possible since 2.0.2
}
Example :
public class ModelResult {
String Ques;
String Ans;
public String getQues() {
return Ques;
}
public void setQues(String ques) {
Ques = ques;
}
public String getAns() {
return Ans;
}
public void setAns(String ans) {
Ans = ans;
}
public ModelResult(String ques, String ans) {
super();
Ques = ques;
Ans = ans;
}
public ModelResult() {
super();
// TODO Auto-generated constructor stub
}
}
your missing part may be this
public ModelResult() {
super();
// TODO Auto-generated constructor stub
}
I searched around and couldn't find anything on the web, which is why I posted this question. My hope is that it'll point others who are experiencing this in the correct direction.
As it turns out, the cause was a new Realm model I'd just created that hadn't exposed a default constructor. As soon as it occurred to me, I added the default constructor to the Realm model, and the build error disappeared.
So, check your Realm models for missing default constructors if you're getting this error during a build!

espresso test ignores IdlingResouce isIdle() returning false

There is an IdlingResource, e.g. like this
public class IRWatchlistNamesLoaded implements IdlingResource {
private final static String CLASSNAME = "IRWatchlistNamesLoaded";
private ResourceCallback callback;
public IRWatchlistNamesLoaded () {}
#Override
public String getName() {
return getClass().getName();
}
#Override
public boolean isIdleNow() {
if(LMaxApplication.watchlists.getNames() != null && LMaxApplication.watchlists.getNames().size() > 0) {
callback.onTransitionToIdle();
CustomLog.print(CustomLog.UI_TEST, CLASSNAME, "isIdleNow = TRUE. size = " + LMaxApplication.watchlists.getNames().size());
return true;
}
CustomLog.print(CustomLog.UI_TEST, CLASSNAME, "isIdleNow = FALSE. size = " + LMaxApplication.watchlists.getNames().size());
return false;
}
#Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.callback = resourceCallback;
}
}
And the usage is standard - when I need the resource I call
watchlistLoadedIR = new IRWatchlistNamesLoaded();
needToUnregisterWatchlistLoadedIR = true;
Espresso.registerIdlingResources(watchlistLoadedIR);
What I see in logs is that isIdle() returns false (1 or 2 times), my test keeps going and my resource is not loaded properly, so test fails. Also, need to notice that in some other tests this IdlingResource works and espresso really waits for the resource to be idle. The usage is absolutely the same.
Please, maybe somebody has any idea why this could happen?
I don't know if this will help but there is a great way of setting up IdlingResources described here which might help solve your problem. I have a sneaking suspicion that it has to do with the fact that you are instantiating your class within the test, which I don't think is what you want to be doing, since you need to be using the IdlingResources from with an activity, using onView to perform action on different components which would then end up running the class in question.

I used following code for downloading xml file from ftp in android it is giving exception? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
I'm new to android, I used code from this site http://www.devx.com/wireless/Article/39810/1954 it is throwing exception while establishing connection with ftp.
public class ClsTest {
private int intid;
public int getIntid () {
return intid;
}
public void setIntid (int intid) {
this.intid = intid;
}
public static void main (String[] args) {
List<ClsTest> objtest = new ArrayList<ClsTest>();
objtest.add(new ClsTest());
}
}
The example below defines a ClsTest class with a single int field. To try this, copy the code into a file called ClsTest.java.
The Object.equals and Object.hashCode methods are overridden so that ClsTest instances can participate in Collections in the way you probably want. That is, I expect you want two instances of ClsTest to be considered equal if they have the same intid.
Try commenting out the equals method to see what happens with List.contains if you don't have it.
We don't exercise hashCode in this example, but it would be needed if you were including your objects in a Map. You should always implement equals and hashCode to complement each other.
Finally, in the main method, a ClsTest object is created and added to a strongly typed List.
import java.util.ArrayList;
import java.util.List;
public class ClsTest {
private final int intid;
public ClsTest(int intid) {
this.intid = intid;
}
public boolean equals(Object o) {
if (this == o) return true;
if (! (o instanceof ClsTest)) {
return false;
}
ClsTest that = (ClsTest)o;
return this.intid == that.intid;
}
public int hashCode() {
return intid;
}
public static void main(String[] args) {
ClsTest objtest = new ClsTest(1);
List<ClsTest> list = new ArrayList<ClsTest>();
list.add(objtest);
// because we implemented equals, this returns true
boolean b = list.contains(new ClsTest(1));
// see what happens if you comment out ClsTst.equals
System.err.println(b);
}
}

Categories

Resources