I am a beginner in blackberry app development.
I had installed the blackberry plugin in eclipse successfully. my first app needs to load html files from a folder I had created named "assets" inside my project. so how can I load the html file "assets/index.html"?
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
Ramadanclass theApp = new Ramadanclass();
theApp.enterEventDispatcher();
}
mainscreen:
public final class Ramadan extends MainScreen
{
public Ramadan()
{
setTitle("Ramadan");
}
}
Edit: what I tried:
BrowserField myBrowserField = new BrowserField();
add(myBrowserField);
myBrowserField.requestContent("assets/index.html");
which had this error
no navigation request handler for assets/index.html
As the link that #Turdnugget supplied says:
The BrowserField class does not access resources using a folder structure. The BrowserField class displays the first resource found that matches the specifed file name.
That means that even if you put index.html into an assets folder, the BlackBerry build process and/or runtime will flatten out (i.e. ignore) your directory structure and therefore you'll have to load the html file with:
myBrowserField.requestContent("local:///index.html");
As you can imagine, this works ok if you only have one file named index.html in your project, but if you have two files with that name, in different folders, the browser field may not load the one you want. I have projects where I do have different versions of html files that are loaded depending on the device, or the version of the app (full vs. free). So, I like to be able to store my html resources in different folders.
To accomplish this, I've used the following code with BrowserField:
browser = new BrowserField();
add(browser);
InputStream content = getClass().getResourceAsStream("/resourcesWeb/index.html");
try {
byte[] html = IOUtilities.streamToBytes(content);
browser.displayContent(new String(html), "http://localhost");
} catch (IOException e) {
e.printStackTrace();
}
For this to work, I store the file index.html in a folder named resourcesWeb (name it whatever you like), and that folder is located inside the top-level res folder.
Note that this is not Android. There is not normally an assets directory. When you use the BlackBerry Eclipse plug-in to create a new project, it creates a src and a res folder for you. I would use that. Create a new project if you need to. Then, keep all non-source code resources (html, xml, images, etc.) somewhere under the res folder.
If you didn't create your project this way, you may find that your app is built without including the assets folder you created. You can probably fix this by right clicking on your project in Eclipse, and selecting Properties. You can add the assets folder to the Build Path using this dialog:
and notice that assets should show up in the Order and Export tab as well.
However, I think it's easiest just to create and use projects the way the BlackBerry Eclipse plugin wants to. This will also make your projects more familiar to other BlackBerry Java developers that see your code. In my opinion, you should save Android naming conventions for Android projects.
Related
I want to read a mock RSS feed file to test against in a Xamarin NUnit test for an Android app. The test class has no context so I can't put the file in the Assets folder and do this:
System.IO.Stream strIn = instanceOfAssetManager.Open(feedFile);
It also has no ancestor, so I can't do this:
System.IO.Stream strIn = this.Class.ClassLoader.ResourceAsStream(feedFile);
Any suggestions how I can get to the jolly thing?
This case solved a similar problem for a different platform/setup:
Storing test files in the test project
The test class has no context so I can't put the file in the Assets folder and do this:
Is there a reason you need to use Android Assets? Using .NET Embedded Resources by setting the file's Build action to EmbeddedResource permits greater portability -- it's present on all .NET platforms -- and neatly sidesteps the Android Context issue.
If you need to use Android Assets, then you can use the Android.App.Application.Context property, which is equivalent to the Context.ApplicationContext property, except static and available everywhere.
Check properties of the file. I had to set "Build Action" to AndroidAsset and than you can use instanceOfAssetManager.Open(feedFile);
I have created a static library LibA.a which includes some codes and another static library LibB.a. When I use this static library LibA.a in a new project I get many errors like these:
File1.h no such file or directory.
This file File1.h and others showing error are present in LibB.a.
Edit 1: I am using XCode 4.0.1
Edit 2: Now while creating my static library, I have made the header file public whose methods the user can use in their project. My static library references another static library named XWidget.a. I have added it into my static library's "Link Binary with Libraries" and also in the direct dependency. Then created my static library. Now I am testing my library in a demo project. In Header Search Paths of demo project I have added the path of my static library's public header file.When I run it, the header files which are present in the inner static library XWidget.a are not found. Giving errors like FileA.h: no such file or directory. Should I somehow provide the path of inner static library (XWidget.a) also? If yes then how? Or what else am I missing?
You need to include the header files in the project where you want to interface with the library.
Click on the big project button in Xcode's file management tab on the sidebar, select your target, click Build Phases, and pull down the drop down menu titled "Compile Sources". Then make sure all the necessary .m, not .h, files are there.
I've run into this problem a couple times myself, I hope this helps you!
Where do I place images within my solution?
I usually create Images folder inside Content folder. Most 3rd party components that use .css files search images subdirectory for their images by default.
You could put them in the Content folder, along with your .css files. Or you could create a brand new folder and organize it any way you like.
In the content folder.
We have a separate resources domain that serves up all static content (recommended). In the solution, I just have a 'resources' folder that mimics the structure of the production folder. Easier to deploy using a script. You can create a separate site or vdir on your local web server and map it to this static folder. The location could then be refernced in your project via an app setting (configuration.resourcedomain + "/resources/images/xyz.jpg")
I am trying to distribute a netbeans project however the jar it creates and the contents of the dist folder are dependant on some image files which i included into the project - however these images are not in the dist folder and I cannot workout how to make things work so I can export the project in a distributable format including all the things it needs.
Can somebody please tell me how I can export a project which runs within Netbeans without using the project's /dist folder which includes everything it needs?
Cheers
Andy
One way to achieve this is to add a folder (f.i."resources") in your project's src dir. Then copy the images to that dir. Now the images should get included when you build the project (if I remember correctly). Accessing the files can be accomplished with "getResourceAsStream"...
If whatever resources you are interested in are in the classpath, packaged in the jar, war, or the distribution, you can retrieve them by getting resources.
The convention is indeed to have a directory named 'src/resources' that serves as the root for this. Depending on the amount and scope of the resources you are using you may also want to add a sub-directory hierarchy to keep the organization and state of the resources manageable.
Also, not that a resource can be any file, an image, sound, text, xml, binary, etc. no limitation.
Finally, the call will look like this if you are using an object method:
getClass().getResourceAsStream("resources/myResource") - or - getClass().getResource("resources/myResource")
depends on if you want a stream or just the URI at that point in the code. Typically one would use the URI for delegating the processing of the resource elsewhere and the stream form when you are processing it in-line.
For a class method, you will need to do something more like:
new Object().getClass()...
The think to keep in mind here, is eventually this is resolving to the class loader and it is from that class path that the resource will be fetched.
You can add images the same way:
final Image image0 = Toolkit.getDefaultToolkit().getImage(getClass().getResource("images/1.png"));
I have some JavaScript files, a main HTML file, a main CSS file, and some CSS files that get imported into the main one.
I understand that I can put static files in two places: a) the 'war' folder; or b) the 'public' folder.
Where is the best place to put my static files? Are the two locations treated differently? Is there a 'best practice' on this issue?
The difference between the 2 locations is that files in the public folders are copied by the gwt compiler to the 'your module' folder in the 'war' folder. This is means if you deploy the 'war' (for example via the google plugin to the google appengine) the files from the 'public' folder are not at the toplevel.
For example, if you have an index.html in the 'public' folder with gwt module named 'mymodule' and you deploy it to www.example.com it looks as follows, you need to access it via:
www.example.com/mymodule/index.html
If you have the index.html in the 'war' folder, you get:
www.example.com/index.html
Summarizing. Your landing page should be in the 'war' folder. Resource files used by the landing page can also be stored here (css, images). Any other resource file that is referred to in any gwt module file (or code, like images) should be stored in the 'public' folder related to the gwt module.
The new way of working in GWT is to use the war folder.
But, if you project is a reusable widget library which is used in a GWT application then you should put the resources in the public folder. The compiler will make sure that the files are automatically included in the generated package.
As I see it, it depends on your requirements, but let's start at a speaking example first ...
I find the documentation (should be GWT 2.6.0) about this to be incorrect or at least incomplete/confusing. As I see it (I am not a guru so please correct me if my investigations are wrong!) I am looking at the following example proj structure
myproj/
src/my/gwtproj/
client/
img/
foo1.png
AppClientBundle.java
foo2.png
public/
img/
foo3.png
foo4.png
war/
img/foo5.png
foo6.png
.classpath
.project
Imagine we may (or may not) need to reference such resources in some AppClientBundle interface (or other application reference context):
interfaces AppClientBundle extends ClientBundle {
#Source("img/foo1.png")
ImageResource fooImg();
}
Then it seems to depend on your Requirements, e.g.:
R.a) these resources (like images) are refered to in the application code, e.g. in our AppClientBundle interface via #Source annotations
R.b) these resources are to be grouped by folders, e.g. foo2.png vs. img/foo1.png
R.c) these resources should be available outside some specific application URL context path, e.g. if used as widget library, e.g. http://host1/gwtapp1/foo4.png vs. http://host1/gwtapp2/foo4.png
R.d) these resources need to be application-independently (e.g. externally) URL-referenced, e.g. http://host1/gwtapp1/foo4.png vs. http://host1/foo6.png
Here's what one can do (Possibilities) and it's implications regarding R.* above:
P.1) (generally recommended as I see it) put nicely folder-structured resources under my.gwtproj.client (here e.g. foo1.png)
this way #Source("img/foo1.png")... works fine
in the docs above they speek about some public folder (in my case my.gwtproj.public), but creating it as a package in Eclipse does not me allow this (since public is a reserved Java key word, but creating it via the Navigator view works)
however, this way the #Source above does not work (likely because it's an issue with the relative AppClientBundle file system location)
nevertheless if the resource should be publicly available under the application context one may have to do it via this public folder
P.2) put "ungrouped" resources directly under myproj/war, e.g. projdir/war/foo6.png
this way it can be used/found within annotations, e.g. #Source
and it can be referenced outside the application itself via e.g. http://host1/foo6.png
P.3) put folder-structured resources under myproj/war, e.g. projdir/war/img/foo5.png
in contrast to P.2) #Source("img/foo5.png") would not work anymore