This question already has answers here:
Retrofit 2 example tutorial but GsonConverterFactory display error "Cannot resolve symbol"
(7 answers)
Closed 5 months ago.
I followed this example https://futurestud.io/tutorials/oauth-2-on-android-with-retrofit
public static <S> S createService(
Class<S> serviceClass, final String authToken) {
if (!TextUtils.isEmpty(authToken)) {
AuthenticationInterceptor interceptor =
new AuthenticationInterceptor(authToken);
if (!httpClient.interceptors().contains(interceptor)) {
httpClient.addInterceptor(interceptor);
builder.client(httpClient.build());
retrofit = builder.build();
}
}
return retrofit.create(serviceClass);
}
but at retrofit = builder.build() I got cannot resolve symbol. Please help.
Sometimes when you download projects from a version control system the files get locked, so in my case to solve this i had to uncheck the "only read" box then apply and accept.
Related
This question already has answers here:
Accessing an object property with a dynamically-computed name
(19 answers)
Closed 2 years ago.
I have a configuration json file in my application.
{
"Name":{
"Catgory":{
"Val":{
"Gaby": "122"
},
"Batch":{
"Hede" : "86"
}
}
}
}
I have lot of configurations like the above. But when I try to read that like below, I'm unable to do.
I have imported the file as config in the current file. When I try to read as below I'm able to get the values.
config.Name.Catgory.Val
But in place of Val,if I try to get the value dynamically like
configVal = "Val"
And if I try to call,
config.Name.Catgory.configVal I'm unable to read. Can anyone please help me with this?
You need to use the bracket-notation in order to access values dynamically:
const config = {
"Name":{
"Catgory":{
"Val":{
"Gaby": "122"
},
"Batch":{
"Hede" : "86"
}
}
}
}
let configVal = 'Val';
console.log(config.Name.Catgory[configVal]);
I'm building a weather app using MVVM and retrofit and i recently added a PreferencesFragmentCompat subclass to implement some user settings using the preferences lib. After doing so, my app won't run and i keep getting these few lines of errors :
2020-04-08 00:54:12.346 18079-18079/? E/de.flogaweathe: Unknown bits set in runtime_flags: 0x8000
2020-04-08 00:54:12.410 18079-18079/com.nesoinode.flogaweather E/libc: Access denied finding property "ro.vendor.df.effect.conflict"
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list com.nesoinode.flogaweather
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
2020-04-08 00:54:12.421 18079-18110/com.nesoinode.flogaweather E/Perf: Fail to get file list oat
2020-04-08 00:54:12.422 18079-18110/com.nesoinode.flogaweather E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
I've got no idea what these are and i can't find any specific answers on stack or google.There are no indications on what is causing the error so i can't figure out if i'm doing something wrong or if it is a library issue. Any ideas?
Here's the SettingsFragment where i'm adding the preferences from an xml resource file :
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.settings_prefs)
}
}
And here's how i'm reading some values from the sharedPrefs:
class UnitProviderImpl(context: Context) : UnitProvider {
private val appContext = context.applicationContext
private val preferences:SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(appContext)
override fun getUnitSystem(): String {
val selectedUnitSystemName = preferences.getString(UNIT_SYSTEM_KEY,
UnitSystem.SI.name.toLowerCase(Locale.ROOT))
return selectedUnitSystemName!!
}
}
I managed to figure out a solution to the issue after doing some more research. Firstly, i commented out all the code related to the preferences library (and the lib itself) and run the app again. The run was successful without any errors so that narrowed it down to the androidx.preference:preference-ktx:1.1.0 library itself since my code was reviewed and couldn't find any issues with it. Looking through the preference docs i figured i could try out a beta or alpha version that may have fixed this issue. And lo and behold, after using the androidx.preference:preference-ktx:1.1.0-beta01 beta version and uncommenting the relative code, everything worked once again.
I need a simple way to detect when a target has been found or lost so that I can segue to a different Controller.
This question has been asked in several forums, but there was never a satisfactory answer. This particular post seems to be the most detailed, but it is over three years old.
https://developer.vuforia.com/forum/ios/trackableeventhandler-equivalent-ios
I can't find any documentation related to this on the Vuforia site.
One of the methods that must be implemented by the VuforiaManagerDelegate is:
func vuforiaManager(_ manager: VuforiaManager!, didUpdateWith state: VuforiaState!)
When a target is found (an image is recognized by Vuforia) this property will change from 0 to 1 (or more, if multiple targets are identified):
numberOfTrackableResults
So it is simply a matter of checking if state.numberOfTrackableResults > 0 { your code here }
on TrackableEventHandler script there is a function called OnTrackableStateChanged
you can sign up to this and do whatever you wanna do directly here or in OnTrackingFound();
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED ||
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
}
else
{
OnTrackingLost();
}
}
Another question on migrating code from v3 to v4:
For v3, I had a customized error reporting, using code like this (in the grammar file):
#members {
public void displayRecognitionError(String[] tokenNames,
RecognitionException e) {
String hdr = getErrorHeader(e);
String msg = getErrorMessage(e, tokenNames);
System.out.println("ERR:"+hdr+":"+msg);
errCount += 1;
}
}
In v4, when compiling the generated java files, I am getting the error:
MyParser.java:163: cannot find symbol
symbol : method getErrorMessage(org.antlr.v4.runtime.RecognitionException,java.lang.String[])
location: class MyParser
String msg = getErrorMessage(e, tokenNames);
^
Is this function replaced by some other function in v4? (I saw some questions and answers on ANTLRErrorListener, but I could not get how to use it for my situation.)
The displayRecognitionError method was removed in ANTLR 4, so even if you correct the body of that method it will not do anything. You need to remove the method from your grammar entirely, and implement ANTLRErrorListener instead. The documentation includes a list of classes that implement the interface, so you can reference those and/or extend one of them to produce the desired functionality.
Once you have an instance of an ANTLRErrorListener, you can use the following code to attach it to a Parser instance.
// remove the default error listener
parser.removeErrorListeners();
// add your custom error listener
parser.addErrorListener(listener);
This question already has answers here:
Groovy, get enclosing function's name?
(5 answers)
Closed 8 years ago.
Is it possible to get the name of the current method in Groovy code?
def myMethod() {
// want to get the string myMethod here
}
Thanks
Tim_yates gives you a link to general solution.
This is shorter way to get method name. May be optimized, leawed as is for the sake of clarity.
class A {
def myMethod() {
for (m in new Throwable().stackTrace) {
if (m.className == this.class.name)
return m.methodName
}
}
}
println new A().myMethod()