I am working with this http://www.survivingwithandroid.com/2013/05/build-weather-app-json-http-android.html tutorial to learn how use weather services in my app. I run this tutorial and it works fine. But I've got one problem. Can't load icons. Logcat error is
java.io.FileNotFoundExeption: http://openweathermap.org/img/w/ at libcore.net.http.HttpURLConnectionTmpl.getInputStream(HttpURLConnctionTmpl.java:186)
When I open this link in Chrome I can see the image so I don't know why it can't be found.
code is there https://github.com/survivingwithandroid/Surviving-with-android/tree/master/WeatherApp
Error in line 87 of file "WeatherHttpClient.java"
facing the same issue just change your url like bellow and its working fine
https://openweathermap.org/img/wn/50d#4x.png
You're trying to load a directory as file stream. Not sure why this should cause a FileNotFoundException but it's worth trying with the URL: http://openweathermap.org/img/w/<one-of-the-files>.png
At least the file should be possible to open.
add .png file ext
example
con = (HttpURLConnection) ( new URL(IMG_URL + code +".png")).openConnection();
Related
I have a TextView with an onClick event handler to download an open a PDF file
I have the following code in the response handler.
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(pdfUrl)))
I can see the PDF loading but before it can be read it returns to the app with the error below.
Cannot open PDF
<filename>.pdf cannot be opened
Device properties
ril.model_id: QB13532959
ro.board.platform: exynos5
ro.boot.em.model: SM-J327T1
ro.build.version.sdk: 24
ro.product.brand: samsung
ro.product.manufacturer: samsung
ro.product.model: SM-J327T1
ro.product.name: j3popeltemtr
Thanks to user #CommonsWare I double-checked assumptions and realized there was an error with the PDF URL. The problem has been resolved.
I need to play a gif file from a URL. I am new to android and am using droids on roids library to achieve this.
I tried the following code :
gifImageView.setVisibility(View.VISIBLE);
Uri gifuri = Uri.parse(gifurl);
gifImageView.setImageURI(gifuri);
I wanted the gif to start but instead I see a blank screen/
Everything looks like it would work correctly... Make sure that the phone you're testing your app on is online, and that the URL you are requesting is an image and nothing else. Also, you could try using the Glide Library instead of Droids On Roids.
A very strange behaviour, while writing code for showing GIF image in image-view.
what i am doing is
InputStream is = this.getResources().openRawResource(R.drawable.logo);
logo is gif image that is in the drawable folder.
when I write that line of code in Eclipse , image loads successfully but when I import that code on Android Studio What I am seeing is an error on R.drawable.logo
and the error is
Expected Resource of type raw
supplying the wrong type of resource identifier. For Example when calling Resources.getString(int id), You should be passing R.string.something not R.drawable.something
one code runs on Eclipse not on Android Studio
I am sure that no problem with the imports.
After doing some R&D i have found a work-around for that
and that is instead of creating drawable folder and put that image into it
create assets folder in main/src/assests and paste that image and then open Input steam.
InputStream is = context.getAssets().open("logo.gif");
that worked for me but sill dont know the answer why
InputStream is = this.getResources().openRawResource(R.drawable.logo);
was not working.
you can try using ion https://github.com/koush/ion#load-an-image-into-an-imageview is a nice library for load images and support gif from local store , resorces or from Url.
Simple solution is using Glide library
compile 'com.github.bumptech.glide:glide:4.3.1'
And Load your ImageView
Glide.with(YourActivity.this).load(R.drawable.your_gif).into(yourImageView);
I have a problem now regarding about the json that can't be read in my android..
the json file is where my data is place..it act as an static database..
I can get it with my Desktop but when it come to my mobile it didn't show..
Here is my sample code:
Here is my Services to get my json file..
var serviceUrl = '/';
$http.get(serviceUrl + 'JSON/Books.json').success(function (results) {
$scope.New = results;
});
Please help me to solve this problem.. my idea about the problem is the serviceUrl. Any idea about it. Thank you so much..
Im definitely a beginner for this Ionic Framework.
To all who still in this problem I just find something that solve it. I don't know if it will solve in your problem but it really solve in me.. I use file:///android_asset/www/ as my serviceUrl
So this is an example:
var serviceUrl = 'file:///android_asset/www/';
$http.get(serviceUrl + 'JSON/Books.json').success(function (results) {
$scope.New = results;
});
Just try it and explore to it.. i just tried that one and it worked in me..
Maybe the reason is the all the json file in your apk installer will be placed in file:///android_asset/www/json directory in android phone so let your url point to that directory..
I hope it will help you and explore in it..that might not be the correct answer but i hope it will help you find the hint.
Thank you
Starting the serviceUrl with a '/' makes it an absolute URL. It will work in chrome since the root is the www folder. But in cordova mobile environment it will translate to file:///.
Simply add a '.' ('./') to make it a relative path and it will work in both android and ios environments.
another easy way is to turn your json file into a javascript file, (for static files if you want to update use something like pouchdb).
eg save the json document as myjsondata.js
var mynamespace = mynamespace || {};
mynamespace.data = [{"foo":"bar"}];
then reference the javascript file in you main page where you load all the other js files
<script src="js/myjsondata.js"></script>
then in your service you can just access the json with mynamespave.data
Based on #Datz Me answer, I've found it's way easier if you treat your application as a web server (which it is) and request your file as being served by it instead of trying to figure out how to manage the different file paths between the several builds.
Here is what I did.
I've placed my json file on
www/json/app.json
Inside it I've put
{
"title": "Application Title",
"icon" : "custom-icon.png"
}
And in my app controller I used the following code to read the properties:
$http.get('json/app.json').success(function (results) {
$rootScope.title = results.title;
$rootScope.icon = results.icon;
});
And in all my child controllers, I just need to add $rootScope as a dependency and I'm able to use
{{title}} //on headings
{{icon}} //to display the image path
<img src="{{icon}}"/> //to display the icon
In my case, it's an app that will be customised for several clients, so I needed a way to quickly change the app's properties and keep them in one place.
i have downloaded the phonegap example from its website.but it doesn't run.i can't find the reason.help me to get the solution please.when i run it shows
"The Web page at file:///andriod_asset/www/index.html could not be loaded as:
The requested file was not found.www/index.html"
I tried with three "///" instead of four, it worked for me. Give a try
super.loadUrl("file:///android_asset/www/index.html");
You've spelt android wrong here:
HERE!!!
file://>>>>>>andriod<<<<<<_asset/www/index.html could not be loaded as: The requested file was not found.www/index.html"
Try out:
file:///android_asset/www/index.html could not be loaded as: The requested file was not found.www/index.html"
Best of luck!
Just a quick comment for other's getting to this same problem, who doesn't have the spelling error. My new app using PhoneGap 0.9.4 was giving this same error box. The solution was to rename phonegap.0.9.4.js and phonegap.0.9.4.jar to just phonegap.jar and phonegap.js. After that it loads up.
You and I did the exact same thing -- flipped the i and the o in android.
Change "andriod" to "android" and it should work :)
I was using capitals for the folder WWW which was causing the same error to be thrown. I have now changed it to lowercase which works well now.