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..!
Related
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
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
I have two projects. One written fully in Kotlin that exports a Client artifact. I am trying to use the client in a second project that has a mix of java/kotlin code.
In the java classes I have no problem importing the kotlin files for use, but in any kotlin files, IntelliJ cannot resolve the imports. All the other kotlin code works fine and I can compile on the command line via maven with no problems. It's just an issue with IntelliJ not recognizing the package I'm looking for.
I see the package in both my maven toolbar as well as in the external libraries listed in the project. I've inspected the jars and sure enough the file I expect com/foo/bar/BazClient.class is present, but
import com.foo.bar.BazClient tells me the package bar (the code from the other project) does not exist. The very same import statement works just fine in java code.
Further adding to my problems the exact same java class that imports this client, if I convert to kotlin using IJ's builtin method, fails to compile in IntelliJ. The "build project" action completes successfully with no warnings/errors.
Kotlin client is defined as:
package com.foo.bar
import retrofit2.http.GET
interface BazClient {
#GET("/v1/fuzz")
fun getFuzz(): Call<FuzzResponse>
}
Working java code:
package com.whodat.wat;
import javax.inject.Singleton;
import com.foo.bar.BazClient;
#Singleton
public class CallTheService {
private final BazClient bazClient;
public CallTheService(BazClient bazClient) {
this.bazClient = bazClient;
}
public FuzzResponse callIt() throws IOException {
return bazClient.getFuzz().execute().body();
}
}
Failing kotlin code:
package com.whodat.wat
import javax.inject.Singleton
import com.foo.bar.BazClient // "bar" is red in editor
#Singleton
// Can't resolve "BazClient" here
class CallTheService(private val bazClient: BazClient) {
fun callIt(): FuzzResponse {
return bazClient.getFuzz().execute().body()!!
}
}
It turns out this was a problem in publishing the client artifact. We were using the maven shade and jar plugins to create the jars and was leading to many kotlin_modules in the jar which were confusing IJ
META-INF/client.kotlin_module
META-INF/descriptors.jvm.kotlin_module
META-INF/descriptors.kotlin_module
META-INF/descriptors.runtime.kotlin_module
META-INF/deserialization.kotlin_module
META-INF/kotlin-reflect-api.kotlin_module
META-INF/metadata.jvm.kotlin_module
META-INF/metadata.kotlin_module
META-INF/util.runtime.kotlin_module
META-INF/kotlin-stdlib.kotlin_module
META-INF/kotlin-stdlib_coroutinesExperimental.kotlin_module
META-INF/kotlin-stdlib-common.kotlin_module
META-INF/kotlin-stdlib-common-coroutines.kotlin_module
META-INF/kotlin-stdlib-jdk8.kotlin_module
META-INF/kotlin-stdlib-jdk7.kotlin_module
Removing those from the client build seems to have cleared things up, and now we just have the one client.kotlin_module.
This problem has a ticket in Jetbrains issue tracker. The ticket has not been resolved yet, but support said:
This is a known problem since the 1.2.50 release of the Kotlin plugin:
KT-25709. As a workaround, please stop bundling the Kotlin
runtime in the dependency jar (i.e. everything under the package
kotlin should be removed from the jar)
I'm trying to work my way through ThinMatrix's Open Gl Java tutorial. And... I'm stuck on video 1. I also worked through the short precursor video where he installed on the dependencies (Including lwjgl 2) in eclipse. Right now I just have the very start of the first class:
package renderEngine;
import org.lwjgl.opengl.Display; //Error is here
import org.lwjgl.opengl.DisplayMode; //And here
//Handle the window
public class DisplayManager {
//Create a display
public static void createDisplay() {
Display.setDisplayMode(new DisplayMode());
}
}
I receive the error, "The import org cannot be resolved". Even though I've added the files to the build path config and I've added the native path in there as well. I've looked at this similar question and effectively tried every proposed solution. I've also tried deleting the project and reinstalling the dependencies. Here is my file tree for reference:
I'd be highly grateful if you could show me what I've done wrong. Thanks so much.
Edit 1:
I've discovered something interesting concerning the line:
Display.setDisplayMode(new DisplayMode());
While both Display and DisplayMode are underlined in red because the import is not working above, one of the "quick fixes" that comes up (even if I delete the import statements) is:
Import 'Display' (org.lwjgl.opengl)
Clicking this writes the import statement at the top (if it isn't there) or brings the cursor to it (if it is there). It then throws the aforementioned error. This seems to indicate that it does actually recognize the fact that the libraries are there, but for some reason can't import them.
The plot thickens.
Edit 2:
To check whether the problem is specifically to do with compatibility with lwjgl2 I've tried importing a class from another library (a linear algebra library called "jblas") with:
import org.jblas.Info;
...but once again I receive the same error. I guess this indicates that the problem is with the way that I am adding the scripts to the build path, with the software itself or a combination thereof.
To clarify how I put things on the build path:
Right click project name -> click "build path" -> click "configure build path" -> click "libraries" -> click on eiether "module path" or "class path" (I've tried both) -> click "add jars" -> navigate to my "lib" folder -> go inside "jars" folder -> select all the jars -> click "apply and close".
Edit 3:
I can import the built-in packages and I can import packages that I've made.
EDIT: DON'T DO THE FOLLOWING: LOOK AT THE EDIT
I downgraded my eclipse version to Oxygen, now I can import the packages without errors. Hopefully, this is remedied eventually so that I can move to the latest version of eclipse. Also, even in oxygen, it didn't work at first. I created a new project and reimported the various jars.
Edit: I faced this problem again, in oxygen
Fortunately this time I resolved it more quickly. I simply added the following snippet to my module-info.jar:
requires org.lwjgl;
Yep it was that simple.
was probably the problem the first time as well. This second problem arose from a second project I decided to make. The last project didn't have a module-info.jar.
That's why it allowed me to not write that line. Meanwhile, the original projects in eclipse 2018/19 did have the module-info.jar file and did have the problem. Maybe in Oxygen it just doesn't happen by default?
I am on Android Studio 1.5.1
falnatsheh/MarkdownView
In the project's readme at github its gives instructions for use. These don't cover actually adding the project .. and I am learning Android programming (in fact I am making an app to keep my notes, as a sort of second step after "hello world").
how do I add it to the project so that I can follow the instructions on the project's readme? My default attempt was to follow these instructions:
File -> New -> Import Module .. add as ":markdownview" in my case, add it to the app's build.gradle, and then that should be it according to the site.
But that doesn't work:
The project's readme starts by saying you should add "compile 'us.feras.mdv:markdownview:1.1.0'" to the dependencies file (I am assuming they mean the Module:app one)... which looks like another way to add ":markdownview" to me.. but I did that too (and that instead of the ":markdownview"). Still the symbol does not resolve.
how do I add it to the project so that I can follow the instructions on the project's readme?
Add the following to your app/build.gradle file:
dependencies {
compile 'us.feras.mdv:markdownview:1.1.0'
}
which looks like another way to add ":markdownview" to me
Not exactly, but close.
but I did that too (and that instead of the ":markdownview"). Still the symbol does not resolve.
As with everything else in Java, you need to add an import statement.
I just created a scrap project in Android Studio, accepting all defaults in the new-project wizard. I pasted the above snippet in app/build.gradle and let Android Studio sync with the project files. I then added a reference to MarkdownView in the Java file, and Android Studio picked up the import without issue.