I'm new to kotlin, I Have an adapter class and I need to inflate a view. but recently I'm facing an error saying "Unresolved reference: R"
Like in the image below :
So, how can I inflate this view? I have imported the following:
import kotlinx.android.synthetic.main.slide_layout.view.*
But I can't figure out what should i do next, I searched everywhere, but they all seem outdated! so what should i do? Thank you!
There are two possible issues i can think of,
The first is a missing import to the R class, if your adapter is in an inner package from your domain package name, i.e.
assume this is the domain package 'your.doamin.package'
if adapter is not in that package i.e. adapter is in 'your.domain.package.adapter'
then you need to import the R class into that file, i.e write this import statement
import your.domain.package.R
That should fix your problem for this scenario
If you have already done '1' above then the other issue is, Sometimes Android studio just misbehaves, so close the file and clean and build your project by first clicking, Build -> Clean Project, once the build is done reopen that file.
For resolving the error unresolved reference: R, you are missing import of your R file. Something like
import packageName.R
For your reference, I am attaching a screenshot of the error and see the commented import.
So check where your R.java resides and import that.
First you check your class import statement in that your R class file imported or not.
import packageName.R
also you can set android studio provide auto import features. if you can enable this feature then all required class automatically import your .kt class
Unfortunately not all answers here can solve your problem, I've been looking for general solutions, you can find them
Here
Related
I currently have a gradle project where I have a line implementation "com.jayway.jsonpath:json-path:2.4.0" in my build.gradle file. In my code, I have an import statement import org.springframework.data.web.JsonPath;, but when I actually use the JsonPath e.g. obj.put("key", JsonPath.read(jsonStr, "key1.key2.key3.key4"));, the read method appears as red in my IDE saying that it "Cannot resolve method 'read' in 'JsonPath'". I have tried refreshing gradle dependencies and closing/opening the IDE/window but nothing works - any thoughts?
remove this
import org.springframework.data.web.JsonPath;
use this
import com.jayway.jsonpath.JsonPath;
Read this documentation to know more about available methods.
Hope this helps.
I am trying to import a custom jar in the node-red java function (https://flows.nodered.org/node/node-red-contrib-java-function), but it is throwing an exception. I debugged and found that the code is added to a test class generated by node red. There are default imports in the class but I cannot find the template used for this pallete.
Any help/pointers are appreciated.
Just FYI for anyone who comes on this path, the java-function node code was updated to let you include custom jars and import statements. This resolves the question
This is my project stricture :
-com.android.test
--com.android.test.activity
---MainActivity.java
---SplashActivity.java
--com.android.test.ui
---ActivityBase.java
I created all activity in com.android.test.activity package and all activities extended from Base activity in com.android.test.ui package
But i don't know , when i creating activities on com.android.test.activity i see .R error in my Eclips , but when i creating activity on com.android.test package ,no need for importing the .R class.
I'm very beginner , please help
When you build an android project, the build tools generate a class called R.java. Because R is a class, it will exist in a package, just like all your other classes. By default, R will be generated in the package you've specified as the project package. For you, this should be com.android.test.
So your package structure is actually like this, even though R is in gen/, not src/.
-com.android.test
--R.java
--com.android.test.activity
---MainActivity.java
---SplashActivity.java
--com.android.test.ui
---ActivityBase.java
In Java, you will require an import statement if a class is not declared inside the package of the current class. So because com.android.test is not contained in com.android.test.activity, you will need to add import com.android.test.R; to MainActivity and SplashActivity, in order to use R in them.
If R is not being generated for you, check out Developing for Android in Eclipse: R.java not regenerating. I would possibly recommend learning to use IntelliJ IDEA, as I've encountered fewer strange build issues than in eclipse, but this is completely optional.
Another possible source of error is if you accidentally imported android.R, which is where the resources of the android SDK are referenced from. This could easily mess you up, since you could write code like R.string.foo and think you are using com.android.test.R.string.foo, but in reality, you are using android.R.string.foo, which may not exist. An easy way to find the problem is to explicitly say in your code, for example:
// you were originally getting an error here
MyActivity.this.getString(R.string.foo);
// try this to get a more obvious error, or see if it fixes it
MyActivity.this.getString(com.android.test.R.string.foo);
I am using a code sample that suppose to be working, but I keep get an error with those 3 import statement.
import com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable;
import com.amazonaws.services.s3.transfer.internal.PutObjectCallable;
import com.amazonaws.services.s3.transfer.internal.TransferStateUpdatingCallable;
the error message says : The import com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable cannot be resolved
why is that happening and how can I solve it ?
Please add jars that contain this classes. This will always solve your problem.
This means that implementations of referenced classes cannot be found in classpath. Since you are using amazonaws you should add appropriate library to your project's dependencies.
Okay, first the project I am working on has two packages, first is murach.business which contains invoiceCalculations.java Second is murach.forms which contain InvoiceForm.java(JFrame) and SwingValidator.java
So, I am supposed to add Add import statements for the murach.business.InvoiceCalculations and java.text.NumberFormat classes in Invoiceformjava that i created from the scratch.
But, I am getting errors when i code that. netbeans says unused code for the below code:
have i written the code incorrectly? whats wrong? Please push in right direction.
import murach.business.InvoiceCalculations;
import java.text.NumberFormat;
"Unused code" doesn't mean that you have a syntax error. It just means that the import is not necessary, because the current code of the class doesn't use the imported class yet. If you add code inside the class that uses the imported class, the warning will disappear.
Note that, with current IDEs, you usually don't bother adding import statements manually. You use the class without importing it, and use a keyboard shortcut (or autocompletion) to add the necessary imports (and remove the unused ones) automatically. In Netbeans, the command is "Fix Imports (Ctrl-Shift-I)"
These are not errors but warnings that Netbeans gives you. The code should still compile fine