I need to know how I can properly add existing Java.class files to an Android Studio Project. My goal is to use these classes in an Android Project.
The Class Files are already written in Eclipse for another Java Project.
I've already tried File->New->New Module->selecting Java Library->Finish but that doesn't work properly.
As you probably all know it makes the MyClass Class by default.
For testing I imported com.example.* in my MainActivity and tried to build an Object of that Class inside the onCreate() Method.
The problem is it can't compile the Project. I got the following Errors:
Error:(7, 1) error: package com.example does not exist
Error:(16, 9) error: cannot find symbol class MyClass
Note: C:\Users\...\MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Can anybody explain how to import my Java.class files correctly so that I can use them in my project?
You can add as a local library package to your project in Android Studio.
In android Project window, right click on app and select New -> Module.
In the Create New Module window, select Java Library and click next. Then give the module name, for example HttpClient in Library Name field. Then give Java package name as same as your existing package com.example.xxx. Then give one existing class file name AnyFileName in Java Class Name field.
Now new module is created with the name HttpClient and the package name is com.example.xxx. With an empty class file Anyfilename.java
Now copy all your .java files to the HttpClient folder created inside your android project. Now it would have overwritten the empty file Anyfilename.java also.
After copying all .java files would have automatically added to the library module.
And you will get 3rd build.gradle file for your module. Already you might be having 2 build.gradle for your android project.
In your app's build.gradle file, include local library dependency compile project(":HttpClient"). Now you can import java files in HttpClient module to android app's java files.
Note : Above information is given based on Android Studio 2.3.3
Related
I am having an Android app that I developed in July 2019 using Eclipse (at least that is what the folder says).
Now I want to make some changes and tried to import and run the project with Eclipse.
But when trying to run the project, I get the following error messages:
These values are required!
userName - login information from codenameone.com
password - the password matching your login from codenameone.com
jarFile - the application jar file resulting from the build
ApplicationDisplayName - display name for the application in the UI
MainClassName - the name of the main class not including the package name
ApplicationPackageName - the package in which the main class resides, this will also be used to classify the application. It is recommended you give this some thought since package names are impossible to change later on some stores!
version - the version number for the application
There is some other strange behaviour, like the error:
The method getAllStyles() is undefined for the type Form
and no Simulator_Project.launch file ...
I have tried refreshing the libraries, but to no avail. Maybe there have changes been made to the build process ...
How can I run the project?
I had a RCP application that uses a plug-in project as dependency. I have added the plug-in project into MANIFEST.MF of my RCP program and it works well. But when I exported the program, it posted an error:
The build.properties is as follows:
output.. = bin/
bin.includes = META-INF/,\
.,\
Application.e4xmi,\
plugin.xml,\
com.hpi.hpdm.console.dependencies;bundle-version="1.0.0"
source.. = src/
source.. = src/
jars.compile.order = .
source.com.hpi.hpdm.console.dependencies;bundle-version="1.0.0"/ =
Comment: com.hpi.hpdm.console.dependencies is the plug-in project, com.hpi.hpdm.console is the main project.
I don't know what "\com.hpi.hpdm.console\"1.0.0"\=" does not exise! means. Any clues will be appreciated.
Updated:
The build.properties:
The .product file Contents tab:
When exporting an RCP your .product file must list every plugin (or feature) that is used by the RCP.
If you are using a feature based product configuration:
Open the feature.xml for your code and add all your plugins to the feature (in your case the feature is 'com.hpi.hpdm.console.feature').
If you are using a plugin based product configuration:
Open the .product file editor and switch to the 'Contents' tab. If your main plugin is listed there you should be able to use the 'Add Required' button to update the list. Make sure that all your plugins have been included (along with a lot of standard Eclipse plugins).
I need help with adding C editor in RCP application. I add needed jars: org.eclipse.cdt.ui and org.eclipse.cdt.ui, in my build path. After this I can recognize class CEditor in plugin.xml -> Extension -> Extension Element Details -> class. I run my application, and when I try to open C file I get this message:
org.eclipse.core.runtime.CoreException: Plug-in "com.ivan.visualizer" was unable to instantiate class "org.eclipse.cdt.internal.ui.editor.CEditor".
Can someone help with this?
You must use the Require-Bundle in your plugin's MANIFEST.MF file to list all the plugins that your plugin uses. Trying to put plugin jars on the build path won't work.
You can set the Require-Bundle in the MANIFEST.MF editor on the 'Dependencies' tab in the 'Required Plugins' section.
I installed QTCreator and Ubuntu SDK as shown here.
When trying to run the code sample provided here, QTCreator tells me it can't find the Ubuntu.Components QML Module.
Notes:
The build-logs says:
file:///home/giladnaaman/Programming/Projects/CurrencyConverter/CurrencyConverter.qml:2 module "Ubuntu.Components" is not installed
But the directory /opt/qt5/imports/Ubuntu/Components
exists (and is full of files).
After adding importPaths: [ "/opt/qt5/imports" ] to the qmlproject file:
QML module does not contain information about components contained in plugins.
QMetaType::registerType: Binary compatibility break -- Type flags for 'QPaintBufferCacheEntry'[1024] don't match. Previously registered TypeFlags(0x103), now registering TypeFlags(0x3).
Do not add the importPaths property to the qmlproject.
Did you setup the QML Scene as your QML viewer?
In Qt Creator, go to Tools > Options…
Choose the External Tools tab, then in the pane select the Preview (qmlviewer) entry
On the Executable: field on the right, replace the contents with /opt/qt5/bin/qmlscene.
Optionally change the command name by double-clicking on the Preview (qmlviewer) entry from above. You can call it Preview (qmlscene).
Click on OK to save the changes.
you’ll be able to view your app through the Tools > External > Qt Quick > Preview (qmlscene)
The Ubuntu SDK is still using the older version of Qt Creator from QT4 it will not be able to locate the Ubuntu Components, and say the components are not found. But the QML Scene used for running the QML GUI will load it and run it without any problems.
I'm trying to use jTwitter to get an oauth instance to twitter with my consumer key/secret and access token/secret. This is well documented in the javadoc here. I have downloaded signpost, signpost-jetty, and the jtwitter library, but after deploying and running the servlet, I get a error java.lang.NoClassDefFoundError: winterwell/jtwitter/OAuthSignpostClient Eclipse isn't complaining about the class not being there, because it is there-- I can see it in the JAR file itself, which is in my project. So, I said forget it, I'll try out OAuthScribeClient instead, but this generated a VERY SIMILAR ERROR java.lang.NoClassDefFoundError: org/scribe/oauth/Token This one confuses me even further because I have the following code in my java file, and it compiles without error or warning:
import org.scribe.oauth.Token;
Token token = new Token("myaccesstokeninfo", "accesstokensecret");
Clearly, I'm missing something very fundamental, but I am at an absolute loss as to what it may be. Thanks.
Usually "NoClassDefFoundError" happens when you forget to copy all jar-files to your "/war/WEB-INF/lib" directory, so those libs will be unavailable from server-side.
Xo4yHaMope is probably right.
If you're working from Eclipse but running using a web container, then your runtime classpath might be different from your project classpath - which can cause this error.
In order to complete Ben Winters answer what I actually did and worked is add the jar in
the libs folder within the project
see also here about folder hierarchy.
When you do this eclipse will normally add the jar to the android dependencies before launching the application. What I realise is that adding a jar in the build path will make classes available only during the build