I am trying to make a project using MVVM.
I've enabled dataBinding by modifying the gradle file.
dataBinding{
enabled = true
}
but after I build my project it doesn't recognize on of my packages.
I tried clean and restart android studio but it does not fix.
If you are trying to import a whole package you should use.
com.example.yourpackage.*
In this case the compiler can understand what you are doing.
If you have created Your viewModel Check the Following.
Have you mentioned Variable in your layout.
Check if you have missed typed any while binding.
clean and Rebuild Project
Goto Gradle->->app->other->dataBindingGenBaseClassesDebug and run it.
This worked for my project.
try this -
import com.example.mvvmLogin.ViewModel.LoginViewModel;`
and at the declaration -
protected LoginViewModel mViewMOdel;
do the same for other activities in the packages
if you are using
import com.example.mvvmLogin.ViewModel.*;
declaration is done by
protected LoginViewModel mViewMOdel;
using protected ViewModel.LoginViewModel mViewMOdel; is not correct
Related
Can anyone help me with this please? Inside my fragment supportFragmentManager.commit{} is not working. Android Studio is not recognizing this I don't know what to do. I am working in kotlin project
That commit {} method (with the transaction in a lambda) is an extension function provided by the Fragment KTX library. If you haven't already, you need to add this dependency in build.gradle:
dependencies {
implementation "androidx.fragment:fragment-ktx:1.2.5"
}
and then Android Studio should automatically offer to fix the commit call by importing it. If it doesn't (it can be awkward sometimes), add this to your imports:
import androidx.fragment.app.commit
and maybe these too, I don't know if they'll be necessary
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
you might need to remove some other matching imports so you're just using the androidx versions
I have imported the latest version of spigot-api to my project, but when i write import org.bukkit.plugin.java.JavaPlugin;, I get a error saying
The type org.bukkit.plugin.java.JavaPlugin is not accessible.
I need help.
Thank you.
RESOLVED: Switching from JavaSE-12 to JavaSE-1.8 worked
First of all, make sure you imported it correctly: Right click on your project > Properties > Java Build Path > Libraries > Add External JARs...
If you already did that, make use of Eclipses quick fix feature. Add extends JavaPlugin to your public class, so it looks like this:
//JavaPlugin will be flagged as an error
public class MainClass extends JavaPlugin {
...
}
Now hover over JavaPlugin, a small menu should pop up, suggesting possible solutions with the first one being Import 'JavaPlugin' (org.bukkit.plugin.java), Click on it and it should import the JavaPlugin object
If both solutions don't work, I'd either suggest updating Java or use Maven, it manages your dependencies and there should be Eclipse/Maven addons for Minecraft plugin developers, to help make the start easier
Teaching myself Java, still very new. Last night I learned how to import this library into my project in Android Studio. But now I'm confused as to how to actually start using it.
I know that Java works with classes and that supposedly a library is just a collection of classes (and probably others things too...) that you can begin using once you import it. But the author of this library told me to just use this:
BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("sendername#gmail.com");
bm.setGmailPassword("sender_email_password");
bm.setMailTo("receiver#gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();
But when I try to put that into another one of my classes, I get red errors all over the place. So then I tried to create a Java class within my app's files and I still got red errors. Could someone kindly help me, a total beginner, get started here? I'd like to use this library to send an email in the background of my app.
To import the library:
I followed this answer: https://stackoverflow.com/a/35369267/5241266 and used Approach 2.
MainActivity.Java: this is where I put the import code.
package moviehelper.moviesfree;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
For now, I have not added the block of code that the author told me to use (see above).
The Gradle Console error:
I get the following error when doing Build -> Make Project:
error: package com.creativityapps.gmailbackgroundlibrary does not exist
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
My project tree: I think there might be some problem with this structure. It looks like the library was added as its own project? Although I'm not sure.
If you don't want to use the JitPack approach as documented in the instructions, then look at the settings.gradle file in the Github example.
It includes both modules (app and the library).
Then, once that is setup, you can compile project(:libraryName) in the app/build.gradle file's dependencies section. Again, see the Github sample for the syntax.
With those two steps (plus one to download the library), it should be importable within the app code.
Assuming you followed along with the other steps on the readme, at the top of your code you need to tell the source file to import the classes:
import com.creativityapps.gmailbackgroundlibrary.BackgroundMail;
public class MainActivity extends AppCompatActivity {
[your code]
}
I would also recommend looking through the sample code included in the github project
You are doing some wrong steps friend. You can follow this
Find your gradle file with name buid.gradle (Project: [ YOUR_PROJECT_NAME ] )
Then find and add this line
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
You are done 50% now. Now press SHIFT+CTRL+ALT+S and wait for a window.
On the Window, select DEPENDENCY TAB on top.
Click on + BUTTON at top right. Click on Library Dependency.
Now paste com.github.yesidlazaro:GmailBackground:1.2.0 there.
Click on OK and exit the window. Gradle recompiles.
Now simply put your code, If RED syntax error showing, Click at the code where error is showing and when a BLUE pop comes, Press ALT+ENTER.
Everything done..!
I currently have an ActionBarActivity which always returns a NoClassDefFoundError. I've read that it might be a problem with the ADT but I cannot be sure, hence my question. I've imported the ActionBar sample from the Android samples under
android-sdk\samples\android-14\ActionBarCompat
I've labelled the ActionBarCompat project as a library under Project -> Properties but I'm still getting the error.
To reiterator:
public class SearchActivity extends ActionBarActivity { // Doesn't work, yields exception
public class SearchActivity extends Activity { // Works perfectly
Has anyone else experienced a similar error and perhaps found a solution?
Thanks in advance.
http://developer.android.com/tools/support-library/setup.html
The "Adding libraries with resources" section may help
since this is not in the most common v4 support library
include only android-support-v4.jar is not enough
Ended up using ActionBarSherlock instead and added a project reference under Project Properties as well as in the Build Path. Seems to have fixed all errors relating to my question.
Just this morning, Google released Android 4.3. They also updated its support library that allows ActionBar to be implemented on lower versions. Just have to extend ActionBarActivity. See guidelines here and tutorial here.
I've got the same problem. I solved it getting the android-support-v7-appcompat.jar library.
See here http://developer.android.com/tools/support-library/setup.html#using-apis how to install it.
I recommend focus on "Adding libraries without resources" instead "Adding libraries with resources" for the sake of simplicity.
When you do it, don't forget to import the this library into your Activity Java source. You can do it declaring import android.support.v7.app.ActionBarActivity;
I solved this problem like so, when you add the library make sure it does not have the android-support-v4 along with it (in libs folder of the library un-check android dependencies and android-support-v4), that's in the case where your project already have the android-support-v4, that's why you can't find class ActionBarActivity
This Link
may help you.
This library is located in the /extras/android/support/v7/appcompat/ directory.
Include in eclipse and add as library. This will solve your problem.
I've just started using Libgdx to practice making games and I used the project creation .jar provided on the site to create the initial projects. However an error shows up in the Android project which says:
android.os.Bundle cannot be resolved.
I am using Eclipse for Java IDE. If I put the cursor over AndroidApplication which is underlined in red, it suggests that I configure the build path. I believe I have the Android SDK installed, because it worked a while back on a different workspace on a simple example project. Does anyone know what I might have done wrong in this new workspace? How can I configure the build path for the AndroidApplication class?
BTW, I believe I'm using Java 1.6 as that's what JAVA_HOME points to, although I've also got Java 1.7 installed. That might not be relevant though...
package com.example.drop;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class MainActivity extends AndroidApplication {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = false;
cfg.useAccelerometer = false;
cfg.useCompass = false;
initialize(new Drop(), cfg);
}
}
The error you are seeing is related to the Android SDK configuration, and is not specific to libGDX. The compiler does not know which Android libraries to compile against.
Use the LibGDX tutorials to setup your projects correctly. (See
https://github.com/libgdx/libgdx/wiki/Manual-project-setup#android-project-setup.
The first step in there does the Android-specific setup.)
If you do not want to create a new project but fix an existing project, the following steps should configure a project to build against Android:
right-click on the project in the Eclipse Package Explorer
select Properties and pick the Android section
Make sure exactly one of the "Project Build Targets" is selected.
That should add the required Android libraries to the build path as a side-effect.
Please, also check to have ADT installed on Eclipse.