Expecting member declaration error and Function invocation 'EditText(...)' expected error - android-studio

I am getting this error on Android Studio which says "Expecting member declaration" on line 8 and "Function invocation 'EditText(...)' expected" on line 11. I am just trying to get the first name from the app UI (activity_main.xml) and save it in this variable. Can someone help me out and tell me what's going wrong ?
I am posting pictures of my code[enter image description here](https://i.stack.imgur.com/XLPUP.jpg)
Tried getting Edit Text value from findViewById

You are using Kotlin, not Java. The way you are doing is in Java.
To declare EditText variable in Kotlin, it can be:
lateinit var firstName: EditText
And the way to set the View to the EditText:
firstName = findViewById<EditText>(R.id.simpleEditText1)
You can read more here.

Related

ViewModelProviders.of(activity) error

I have no idea what to do anymore but ask here.
When i try to access the ViewModel from a fragment attached to an activity:
private val userViewModel by lazy { ViewModelProviders.of(activity).get(UserProfileViewModel::class.java) }
i get an error for "activity" saying "Type mismatch: inferred type is FragmentActivity? but FragmentActivity was expected"
every example i've seen so far is using it this way and i just can't get it to work.
Not sure if this is deprecated and i should just give up on it.
Your problem is, that activity can be null when the viewmodel is lazy loaded, which means the type of activity is FragmentActivity? instead of the required FragmentActivity.
The ViewModel Initialization is usually not done with a delegate, but in a lifecycle method, where you are sure you are attached to an activity, like in onViewCreated() or onActivityCreated().
There you can safely use:
userViewModel = ViewModelProviders.of(activity!!).get(UserProfileViewModel::class.java)

Initializing custom view in Android Studio: Expected resource of type xml

I have a custom view called IconView, which has the following constructor for initialization:
public class IconView extends RelativeLayout implements Checkable {
...
public IconView(Context context, AttributeSet attrs, boolean useDefaultImage) {
super(context, attrs);
inflateLayout(context);
...
In order to initialize AttributeSet instance from XMLfor constructing the view, I use getResources().getXml(R.layout.icon_view), false);.
This compiles successfully and runs correctly. However, Android studio highlights the code and displays me this error:
The detailed description of the error is here:
Expected resource of type xml less... (Ctrl+F1)
Reports two types of problems:
Supplying the wrong type of resource identifier. For example, when
calling Resources.getString(int id), you should be passing
R.string.something, not R.drawable.something.
Passing the wrong
constant to a method which expects one of a specific set of
constants. For example, when calling View#setLayoutDirection, the
parameter must be android.view.View.LAYOUT_DIRECTION_LTR or
android.view.View.LAYOUT_DIRECTION_RTL.
The question:
Although the code works, I do not know, how to rewrite it, so that the error would disappear in Android Studio. The error is visually annoying, so how could I get rid of it?
Resources#getXml(int id) is used to get the resource of type xml, which lays inside the xml resource folder. You, on the other hand, passing R.layout.icon_view here, the layout resource.
Use getResources().getLayout(R.layout.icon_view) here and the error will disappear.
P.S.: the documentation on Resources#getLayout() says the following:
This function is really a simple wrapper for calling getXml(int) with a layout resource.
So it looks like this is some kind of lint-related issue. Either way, getLayout() does not result in this error.

Error calling method in java-class 'ClassA' 'org.my.ClassB' is incompatible with 'org.my.ClassB'

I have two classes org.my.ClassA and org.my.ClassB both classes are in the same package org.my in the WEB-INF/src in the same database.
ClassA has the method public add(org.my.ClassB newB){...}.
In SSJS I have a code block in which I call ClassA.add(ClassB) which normally works fine. Until some unknown point where the Server can't see that org.my.ClassB === org.my.ClassB and it returns the error (message translated from German maybe looks different in English version):
error calling method 'add(org.my.ClassB)' in java-class 'ClassA'.
'org.my.ClassB' is incompatible with 'org.my.ClassB'.
and it points to my line in the SSJS: ClassA.add(ClassB);
What I tried so far:
First I added the line importPackage(org.my); to my SSJS Code. No luck.
I tried to add another method add(Object newB) and then cast the object to ClassB but same result. The error does not seem to come from the java class its from the SSJS code because it cant find the method with an argument of the type org.my.ClassB. But if I test the object in the SSJS code it returns org.my.ClassB.
Then I tried to add the classpath to all variables in the SSJS block like: var newB:org.my.ClassB = new org.my.ClassB(). But same result after some time the application breaks with the same error.
From my Point of view it got to do something with the caching of compiled classes, or so because if I clear the database everything works just fine again.
Hope someone has a solution on this.
This is a class loader problem.
You can find more details about the issue in the answer from Frantisek Kossuth:
See here more details: Meaning of java.lang.ClassCastException: someClass incompatible with someClass

Viewing an object in Locals or Watch window causes excel to crash

In Excel when I'm running some code and put a breakpoint in I can look at the values of things in the locals window. In the locals window, when I try to expand a object for the class I've created Excel Crashes with "Microsoft Office Excel has encountered a problem and needs to close. We are sorry for the inconvinience. This also happens if I try to view the object in the watch window.
Any ideas? Or anyone had this before?
Thanks,
Chris
Check, check again and recheck your class properties, especially your GET code. I had the same error where expanding the a custom class object during debugging caused Excel to crash. Excel essentially runs those GET properties when you expand the object in the locals window, so they must compile and not cause any runtime errors.
Of course I can't say this definitely caused the OP's error without seeing their code, but for me the error was an extremely simple one where a GET property contained a type mismatch:
Private pAccFullArr() As String
Public Property Get accFullArr() As Variant
accFullArr = pAccFullArr
End Property
should have been
Private pAccFullArr() As String
Public Property Get accFullArr() As STRING()
accFullArr = pAccFullArr
End Property

If Statement in Template

I want to create my own template and my code is:
#{if _arg.status.equals(models.Status.FINISHED)}
#{doBody /}
#{/if}
When I pass an object reference to my tag its saying its null. If I call in my template its working as described in the docs:
${_arg.status}
The error message is:
Template execution error
Execution error occured in template
/app/views/tags/isNotFinished.html. Exception raised was
NullPointerException : Cannot get property 'status' on null object.
I am not getting any null pointer exception. What I am doing wrong here?
Thanks for your help.
It seems like _arg is not found in the scope you're working with. This seems to indicate you get arg implicitly in the tag. You might try omitting the _arg. from the tag.
I am not getting it really. But today I tried again with _arg and its working now as excpected. It can be closed now.

Resources