Please Help. Im following tutorial on youtube (channel: coding in flow). Its about making a todo app in kotlin using android studio, and i got stuck on this:
taskDao.update(task.copy(completed = isChecked))
Error: Unresolved reference copy.
Tryed a lot of things but didnt help.
task is most likely an instance of a data class which has its own copy() method. If you have access to this class, make sure it is a data class and not a class.
Related
I want to define my class on frameworks/base/core, and use it as common library.
So what I did was adding a java class file 'MyTime.java' on frameworks/base/core/java/android/text/format folder. However, when I try to import the class, error 'cannot find symbol' occurred.
The code of MyTime class is like below.
package android.text.format;
...
public class MyTime {
...
}
I can't use this class, and tried for days, but still have not found the solution.
Could anyone help me?
This sounds like a bad idea, you are creating a fork of the Android API.
Did you run
make update-api
make sdk
to update frameworks/base/api/*.txt and rebuild framework.jar? If not, it will not be visible to users.
Repeating 1. Please add to a separate library, not the base framework.
I'm currently trying to share data between my two fragments with the help of a view model Android ViewModels.
In the this article they use "ViewModelProviders.of(getActivity()).get(SharedViewModel.class);" in the Fragment to get the model.
My Problem is, that when I write the exact same line into my fragment, I get a "Cannot resolve method of(android.app.Activity)" error
model = ViewModelProviders.of(getActivity()).get(UserAccountViewModel.class);
Can some one help me with this ?
ViewModelProviders requires that you use FragmentActivity (or something derived from it), not Activity, as the base class of your activities.
You might also get a similiar error like Cannot resolve method 'of(android.support.v4.app.FragmentActivity)' from ViewModelProviders.of(getActivity()) if you were trying to import androidx in your gradle file when your app is still using android.support.v4
This is different to the question being asked but is in the same ballpark and ranks first in Google when I had the problem, so I'm posting it!
Just cast getActivity() to specific activity. It works for me. For example:
model = ViewModelProviders.of((MainActivity)getActivity()).get(UserAccountViewModel.class);
can anyone please help me? I am trying to enable Parse Local Datastore in a fragment but its throwing out an error: java.lang.IllegalStateException: Parse#enableLocalDatastore(Context) must be invoked before Parse#initialize(Context, String, String). Below is the code I use which works perfectly fine in an Activity but not in Fragment and I know the getActivity context is not null since the second line works.
Parse.enableLocalDatastore(getActivity());
Parse.initialize(getActivity(), DeveloperKey.ParseAppID, DeveloperKey.ParseClientKey);
you have to move your code related to Parse initialization to the Application class. Make class extending Application, add it to manifest and then in the onCreate() of you application call
Parse.enableLocalDatastore(getActivity());
Parse.initialize(getActivity(), DeveloperKey.ParseAppID, DeveloperKey.ParseClientKey);
Reading your logcat error you just need to interchange your code.
Parse.initialize(getActivity(), DeveloperKey.ParseAppID, DeveloperKey.ParseClientKey);
Parse.enableLocalDatastore(getActivity());
When your parse is enables after that you'l be able to enable your local database for it.
I realised using pin() automatically saves to the local datastore so there was no need to explicitly use enableLocaldatastore(). With this, I can query from localdatastore and get the cached result.
Parse.enableLocalDatastore(getActivity());
is an old way of enabling local datastore.
Now you have to do like this.
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(getResources().getString(R.string.parse_api_key))
.clientKey(null)
.server("YOUR_SERVER_URL/") // The trailing slash is important.
.enableLocalDataStore().build()
);
Try upgrading:
implementation "com.github.parse-community.Parse-SDK-Android:parse:x.xx.x"
To a newer version. Like this:
How android ide did help me out:
I'm using AndroidAnnotations in an Android Studio gradle project. I currently get error output from AA during compilation that says:
cannot find symbol class MyActivity_
The error output does not prevent building the application - its not really a compile error because the class is there, it seems that it is just an unfortunate timing issue with the compilation process.
Is there anything I can do to avoid these false-positive errors from AA? When there are "fake" errors shown every time I compile, its very easy to miss the real errors.
I had same error. To solve it I have revert my last changes and it has worked again.
I think it was either wrong optimized import(you must import generated classes eg. xxx_) or I injected layout by id what was not existed in the layout xml
Update
I figured it. My problem was what I had use private mofidier instead of proteced in
#ViewById(R.id.list)
private ListView list;
Try to see if you missed to fix some errors in the class MainActivity or in someone of his Bean member that you have annoted.
The problem doesn't have to be in MainActivty, but it is probably because of a private modifier which is used with Android Anotations (in injection, method declaration etc) somewhere in your code
I am trying to create unit tests for a REST client that does some API calls. The client works fine in the live application, but I can't get it to run in the test case.
Apparantly, LoaderTestCase.getLoaderResultSynchronously() could be used here (at least according to Android reference, but it will not accept my loader. The code:
public void testGetEventInfo() {
// Init some vars
...
// Create & execute loader
RESTLoader loader = new RESTLoader(getContext(),
RESTLoader.HTTPVerb.GET, action, params, LOADER_GET_NEWS);
getLoaderResultSynchronously(loader);
}
This yields the error getLoaderResultSynchronously(Loader) in the type LoaderTestCase is not applicable for the arguments (RESTLoader).
RESTLoader extends AsyncLoader. Note that I'm using the supportlibrary, maybe the Loader in there is incompatible? The documentation gives no information on this.
I've tried to solve this in several ways, though none seem to work:
Registered a listener to loader. However, the callback never triggers
Using CountdownLatch (also with a listener). Again, no trigger/countdown timeout.
Playing around with the type template (), without success.
Similar solutions on SO, though again failing to reach the listener.
Does anybody know why getLoaderResultSynchronously will not accept the loader? Or another clean way of testing the Loader, including a way to test return data? I can test handling the return data in a separate case, but I would also like to test the actual data.
Sincerely,
Have you taken a look at the source code? You'll find the following import statements:
import android.content.Loader;
import android.content.Loader.OnLoadCompleteListener;
It doesn't look like Android offers a support version for LoaderTestCase. The easiest solution would be to temporarily change to the non-support LoaderManager (that is, have your class make use of the android.content.Loader instead), test your app, and then switch back to the support implementation. You might also consider copying the testing source code into your project, import the support LoaderManager, and execute it directly. I'm not familiar with the test libraries for Loaders but it doesn't seem outwardly obvious that this would cause any major issues.
You can get sources from LoaderTestCase here, create SupportLoaderTestCase class from that sources in your test project and modify all namespaces to support library namespaces (e.g. change android.content.Loader with android.support.v4.content.Loader). Than you can extend your test case from SupportLoaderTestCase (not from LoaderTestCase) and use it without problems
The method you are trying to call (getLoaderResultSynchronously) accepts an object of type android.content.Loader. If your RESTLoader class is not of that EXACT type then you will get this error. I suspect your class directly or indirectly extends android.support.v4.content.Loader, which would explain the error.
I am not aware of a back-port of LoaderTestCase that would support testing of this type of class.