What is the meaning of 'cannot resolve symbol R' error in android studio? - android-studio

When I try to compile my project it says cannot resolve symbol R. why do I get that error? If it's because an xml file is corrupted what is the solution to the above issue?
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.advanced_quiz);
}

This happens all the time to me as well. Especially when going between versions or basically changing anything with Android Studio.
Without more information, I can't give you a definite answer, but typically cleaning and rebuilding the project fixes these issues for me.
Go to "Build", then "Clean Project." After that, go to "Build", then "Rebuild project."
Let me know if that works. If it doesn't, there are other possible solutions I can add.

Related

use Intent in Kotlin

When we want to move to another Activity using Intent in Kotlin, it gives this error.
In Intent, it doesn't recognize .java after ::class
look:
And when I delete .java, Intent gives an error
Note: My problem was not solved with Invalidate Caches / Restart... option in File
I don't know where the problem is. please help me.
Kinda strange because it seems good to me. Try this.
Remove the lateinit and declare it directly when you need it, maybe it will solve the problem.
val intent = Intent(this, LauncherActivity::class.java)
I don't think the this#KotlinActivity is needed in this case.
Let me know if this fix it
UPDATE
Are you sure the findViewById<TextView>... is correct ? Shouldn't it has a declaration before ? Like
val view = findViewById<>...
The solution is:
In build.gradle (:app) file, in dependencies, you should change appcompat version to 1.4.2.
befor error:
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.0'
...
}
And when I changed the version to 1.4.2, the problem was solved
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
...
}
And make sure the kotlin version is 1.5.0

Why everytime open a new flutter project this error appear?

I have tried a different kind of ways to resolve the error but still can't resolve, and I'm still a new learner on flutter. But I still can run the whole project well without resolving the error shown.
There is no error that's just ide warning I think, that could be about typo etc, If you click to lamp and show us the suggestions then we can help more.
But I tried this part of code and get different warning and solved it with add # to override such as;
class MainActivity: FlutterActivity(){
#override fun configureFlutterEngine(#NonNull flutterEngine: FlutterEngine){
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
If that's show same you need to check your ide settings, probably there is a missing plugin(Dart or Flutter).

Disable warning lint for a method in external library in Android Studio

In my Android project I have an external library with following method:
// Some external library
class Foo {
#CheckReturnValue
public final Bar returnBar(Bar bar) {
...
}
}
I have to call this method a lot in my project, but I do not need the returned value of this method. All I need is the side effect of the method. So this is how I use it:
fooInstance.returnBar(barInstance) // ignore returned value
The problem with the above code is that Android Studio editor will show CheckResult warning lint. What I can do is to either just live with that warning lint or disable CheckResult for the entire project or module, but I was wondering if there is a better approach to this warning.
What I cannot do is to put SuppressLint because I will be using that method 100 < times in my project and adding SuppressLint to every single usage is not really feasible.
I already went through Android Studio inspection settings but unfortunately was not able to find anything that can help. I would be grateful if you could provide literally any thought on this problem.

java.lang.VerifyError: me.xxx.menu.MenuListFragment only on Android 2.x.x

after almost 2 week trying to solve this strange problem, I give up!
Basically a get the java.lang.VerifyError every time I try to run my app
only in devices with Android 2.x.x. From 3.x.x all are going well.
In the project I'm using this two external library:
Action Bar Sherlock - http://actionbarsherlock.com/ - updated at the v4.4.0
Sliding Menu - https://github.com/jfeinstein10/SlidingMenu
This is what the LogCat return every time:
FATAL EXCEPTION: main
java.lang.VerifyError: me.xxx.menu.MenuListFragment
at me.xxx.menu.BaseSlidingMenuActivity.onCreate(BaseSlidingMenuActivity.java:46)
at me.xxx.menu.SlidingMenuCustomAnimation.onCreate(SlidingMenuCustomAnimation.java:28)
at me.xxx.XXXActivity.onCreate(XXXActivity.java:130)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
and this is how the BaseSlidingMenuActivity.java looks like around the line 46:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.frame_content);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new MenuListFragment(); <--- ERROR HERE!
t.replace(R.id.frame_content, mFrag);
t.commit();
} else {
mFrag =(SherlockListFragment)this.getSupportFragmentManager()
.findFragmentById(R.id.frame_content);
}
...
...
}
Where MenuListFragment() is a SlidingFragmentActivity that extend a SherlockFragmentActivity
and implements SlidingActivityBase.
Of course I googled the problem, and seems that a lot of people are getting this
issue with the last version of the Android SDK tool, i.e. v22.x.x , in fact a have
the v22.6.3.
Some people resolved the VerifyError just putting the Check on the "Private Libraries"
box, inside "BuildPath->Configure BuildPath->Order and Export" menĂ¹, as explained
in other conversation about the VerifyError, but for me doesn't work, even because the "Private Libraries" was already checked. So the libraries/imports situation seems to be ok!
Hoping that someone already fund a solution for that! I'm getting crazy! :D
Thank you!
I finally found the solution!
Recap! Basically the are two main reason in which you can get this error:
(In my case) I was getting the VerifyError all the time that I tried to run my app on devices with API Level under 10 , because I was trying to catch an SQLiteDatabaseLockedException that are supported from the Android API Level 11. So to solve it check that every Exception or possible method (i.e. String.isEmpty() is supported from API Level 9) is supported form your minimum API Level.
While I was searching for a solution I found a lot of people that got the VerifyError because there was some problem with Libraries Imports, as explained in this post: http://commonsware.com/blog/2013/05/23/do-not-manually-modify-eclipse-build-path-except-now-r22.html
Hope that will help someone beyond me! :D
Bye Bye! Caterpillar.

T4 template shadow copy does not work

I'm using VS2012 and T4 templates and assemblies are supposed to be shadow copied, meaning that you can reference an assembly in a template and then recompile that assembly. But this simply doesn't work for me. When I try it, when I try to rebuild the assembly, I get errors like:
Unable to copy file "obj\Debug\xxx.dll" to "..\bin\xxx.dll".
The process cannot access the file '..\bin\xxx.dll' because it is being used by another process.
The only way around it is to restart Visual Studio, and this is so tedious that I'm ready to abandon T4 entirely. What could I be doing wrong?
So this isn't really an answer yet but hopefully we get there
Test ran the following in VS2013 (I realize you run VS2012)
<## assembly name = "$(SolutionDir)\TestProj\bin\Debug\TestProj.dll"#>
<## import namespace = "TestProj"#>
namespace ConsoleApplication1
{
class <#=Testing.Name#>
{
}
}
The TestProj contains the Testing class
namespace TestProj
{
public static class Testing
{
public static string Name
{
get { return "Tester" ;}
}
}
}
This did work very well in VS2013 and as far as I remember this worked in VS2012 as well.I will try to install VS2012 on one of my machines but do you mind testing this simple sample on your installation to validate it's not something in your solution that holds the dll?
In case you are interested in the project file you can find it here:
https://github.com/mrange/CodeStack/tree/master/q21118821
I work around similar issue. T4 design time template is processed in different App domain under the same process of visual studio. When rebuild the solution Visual Studio tries to replace the referenced DLL, and it cannot replace it because it is still in use.
I work around this issue by deleting the AppDomain in which T4 template is processed. See msdn

Resources