1
This error in my application is happening:
java.lang.Outofmemoryerror: Failed to allocate
my image code:
URL url1 = null;
try {
url1 = new URL("http://www.cm-mgrande.pt" + cabecalho);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream input = url1.openConnection().getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(input);
input.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(url1.openStream()));
in.close();
imgcabecalho.setImageBitmap(bmp);
imgcabecalho.setScaleType(ImageView.ScaleType.FIT_XY);
} catch (IOException e) {
e.printStackTrace();
}
my Android Manifest :
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:largeHeap="true"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Index"
android:configChanges="orientation|screenSize"
android:largeHeap="true"
android:label="@string/app_name" >
</activity>
</application>
What’s that for
BufferedReader
?– ramaral
A good question but at the time I needed to run the code
– Tiago Coelho
In the code you posted it is doing nothing. The error may be that there is not enough memory to allocate the
BufferedReader
. Delete it and try again. If it is not enough see this reply in Soen. It has nothing to do with the error but it will be necessary to include in Manifest.xml access to the internet– ramaral
error copying I am using <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
– Tiago Coelho
I removed the bufferedreader and nothing worked yet
– Tiago Coelho
Is the error the same or another? By forgetfulness I did not put the link to the reply that I mentioned in the other comment.
– ramaral
is the same now tried so Bitmap bmp = Bitmapfactory.decodeStream(input,options); but error in options
– Tiago Coelho
Bitmapfactory.Options options=new Bitmapfactory.Options(); options.inSampleSize=2; Inputstream input = url1.openConnection(). getInputStream(); Bitmap bmp = Bitmapfactory.decodeStream(input,options); input.close();
– Tiago Coelho