I am new to android and i want to import some classes to my application wich are placed in MyClasses folder in same package.
After googling for a time I found a way to do this by usig Java build path and in this add class folder. I think this may solve my problem but no luck.
I don't know how to import classes from folders. Is it possible to import classes from folder? If it is possible then how to do this?
Any help will be appreciated.
I assume this is for Eclipse. You have the options for importing a Class Folder, which is not very useful in my opinion since it only loads folders in projects you have defined in your workspace. In this scenario I would just link to the project itself. But you can also import External Class Folders. If this is what you are trying to accomplish then make sure you are using the correct item in the Java Build Path dialog.
The problem that Dalvik does not understand java files. They should be compiled into the internal Dalvik format dex. And even after that I'm not sure that you can dynamically load files into your project.
Have the folder in your build path, then use:
Class.forName("package.className")
It will also call the static constructor for the classes loaded this way (this pattern is used with JDBC drivers).
If you want to change the folder at runtime, you might have to write your own class loader.
This might help more: http://www.techrepublic.com/article/get-the-most-out-of-javas-class-loaders/6080883
Not sure how this works with Android, though. I don't think you can implement your own class loader for Android due to security issues.
Related
What I mean is, in Java there is a standard set of packages that can be referenced from any program in any context on the computer. So when I want to process raster images I just add import java.awt.image.BufferedImage to the top of my file and I able to use that pre-built class without referencing the actual java.awt.image package files at all during compilation and run time. Where are these globally importable packages kept and/or how can I make my package files globally available in the same way?
I have been writing a lot of small helper programs lately, most of which do very similar things, and it would be convenient for me to be able to reuse code without explicitly referencing my package files.
Thanks for any help.
you CAN place any jar library you want into your JRE to achieve same result - classes from this jar will be available in classpath at runtime though it is not recommended to do so without a reason :) But if you are just learning and do not want bother with build tools it's OK
[java-home]/lib/ext - standart place for your libraries
[java-home]/lib/endorsed - place for the libraries which API's overwrite default JRE's ones
This is part of a demo code, I am trying to learn this code
import com.jgrindall.android.connect4.lib.board.*;
What is this code doing? is a lib a folder? if it is a folder then where is it located?
It's importing all classes in the com.jgrindall.android.connect4.lib.board package. The source for this can vary - I assume it's in the com/jgrindall/android/connect4/lib/board source folders but sometimes it refers to code in an existing jar library used in the project.
Import means you want to be able to use the named classes without having to specify their full qualified name. In particular, since this import ends in *, you're saying you want to be able to use any class in the com.jgrindall.android.connect4.lib.board package by just giving the short classname -- Board rather than com.jgrindall.android.connect4.lib.board.Board
Where those classes are loaded from is a separate question, determined by your classpath and classloaders.
it is importing a PAKAGE. You can see the package as folder, and the ending wildchar means import all class in the packge.
If you are using plain source code, then package are folder, but they can also be packaged (no pun intended) in a jar. you can open a jar as a zip, and you will se a manifest file, and thepackage structure.
Also there ase some standard class in their own package in the visrtual machine, and they are all the standard library
I am programming in java using Eclipse, I am a novice and I'm stuck with the following problem: I have an Eclipse project that uses an external jar library. In this library there is a specific class that needs to be temporarily modified. I have the source code for this class. Is it possible to somehow include the source file for the code into the project, so that it will "override" the corresponding class in the jar file?
Thank you.
Basically, it's not possible to have two classes with the same signature (package + name) in the classpath but it's possible to import this class in your project in different package and use it instead of the original one.
Another way to solve this problem is to edit the .jar file by removing or changing the class that you need to be different.
However, note that changing an API is almost never a good idea.
I was about to report a but to Eclipse, but I was thinking to give this a chance here first:
If I add an external package, the application cannot find the referenced native library, except in the case specified at the below:
If my workspace consists of a single project, and I import an external package 'EX_package.jar' from a folder outside of the project folder, I can assign a folder to the native library location via:
mouse over package ->
right click ->
properties ->
Native Library ->
Enter your folder.
This does not work. In runtime the application does not load the library, System.mapLibraryName(Path) also does not work.
Further more, if I create a User Library, and add the package to it and define a folder for the native library it still does not.
If it works for you then I have a major bug since it does not work on my computer I test this in any combination I could think of, including adding the path to the windows PATH parameter, and so many other ways I can't even start to remember, nothing worked, I played with this for hours and had a colleague try to assist me, but we both came up empty.
Further more, if I have a main project that is dependent on few other projects in my workspace, and they all need to use the same 'EX_package.jar' I MUST supply a HARD COPY INTO EACH OF THEM, it will ONLY (I can't stress the ONLYNESS, I got freaked out by this) work if I have a hard copy of the package in ALL of the project folders that the main project has a dependency on, and ONLY if I configure the Native path in each of them!!
This also didn't do the trick.
please tell me there is a solution to this, this drives me nuts...
Update:
if anyone wants to try this for them selfs you can try to use JMF.jar and to refer to the native dlls, or the jmf.properties file, on my XP, I refer to the dll files and I don't need the jmf.properties file.
Thanks,
Adam Zehavi.
I missed the point that Eclipse does not export the native library.
here is a solution to what I was facing: Other answer
I'm at school and we are doing this java stuff. We use a special library named sum.kern: http://www.mg-werl.de/sum/bjw.zip
I want to use Groovy instead of Java. But I can't get groovy to use this library. If I add the jar in grape and try to import sum.kern and create a sum.kern.Bildschirm it says that it is not able to find it. How to do it?
I don't think it should be a problem, its pretty straight forward. The only requirement is to have the library in your classpath.
Are you able to import the package successfully?
It doesn't matter though, What IDE are you using, BTW?
You should have a "groovy-starter.conf" file that specifies the directories in which groovy looks for jar files. It should be in the "conf" directory within groovy.home (for example, on my machine it is "C:\groovy\Groovy-1.5.6\conf\groovy-starter.conf").
If the jar file containing the classes you want to import are within one of these directories, you should be able to import it no problem. Alternatively, you could add the directory that the jar is currently in to your groovy-starter.conf file.