user4003509
user4003509

Reputation:

Can't successfully load image from Assets folder in Android

In my code I have no errors, no warnings at all but when I load a layout trying to display a thumbnail photo, located in Assets folder I can't see my image("25.png")displayed in my layout.

My Java file is :

import android.app.Activity;
import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

public class Museum_Exhibit_Info extends Activity {

    ImageView mImage;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.exhibit_info);
        mImage = (ImageView)findViewById(R.id.mImage);
        loadDataFromAsset();

    }

        public void loadDataFromAsset() {

        // load image 
        try {
            // get input stream
            InputStream ims = getAssets().open("25.png");
            // load image as Drawable
            Drawable d = Drawable.createFromStream(ims, null);
            // set image to ImageView
            mImage.setImageDrawable(d);
        }
        catch(IOException ex) {
            return;
        }

    }

}

And my xml file is :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

    <ImageView
        android:id="@+id/mImage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/assets_image_number_25"
        />

</LinearLayout>

I truly don't understand what the problem is.

My Logcat is (from launching my app..during runtime):

    02-26 16:54:42.827: I/QCAR(2882): Configure Video Background : Video (640,480), Screen (1080,1920), mSize (1440,1920)
02-26 16:54:42.927: D/dalvikvm(2882): GC_EXPLICIT freed 536K, 17% free 22671K/27228K, paused 4ms+8ms, total 39ms
02-26 16:54:43.488: I/Choreographer(2882): Skipped 60 frames!  The application may be doing too much work on its main thread.
02-26 16:54:43.498: E/BufferQueue(2882): [unnamed-2882-1] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeudCount=0)
02-26 16:54:43.498: E/BufferQueue(2882): [unnamed-2882-1] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeudCount=1)
02-26 16:54:43.728: I/Adreno-EGL(2882): <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build:  (CL3869936)
02-26 16:54:43.728: I/Adreno-EGL(2882): OpenGL ES Shader Compiler Version: 17.01.11.SPL
02-26 16:54:43.728: I/Adreno-EGL(2882): Build Date: 01/17/14 Fri
02-26 16:54:43.728: I/Adreno-EGL(2882): Local Branch: 
02-26 16:54:43.728: I/Adreno-EGL(2882): Remote Branch: 
02-26 16:54:43.728: I/Adreno-EGL(2882): Local Patches: 
02-26 16:54:43.728: I/Adreno-EGL(2882): Reconstruct Branch: 
02-26 16:54:43.728: I/QCAR(2882): Creating OpenGL ES 2.0 context
02-26 16:54:43.838: D/QCAR(2882): GLRenderer::onSurfaceCreated
02-26 16:54:43.838: I/QCAR(2882): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_initRendering
02-26 16:54:43.858: D/QCAR(2882): GLRenderer::onSurfaceChanged
02-26 16:54:43.858: I/QCAR(2882): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering
02-26 16:54:43.858: I/QCAR(2882): Configure Video Background : Video (640,480), Screen (1080,1920), mSize (1440,1920)
02-26 16:54:43.858: D/QCAR(2882): ImageTargets::updateRenderView
02-26 16:54:43.858: I/QCAR(2882): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_updateRendering
02-26 16:54:43.858: I/QCAR(2882): Configure Video Background : Video (640,480), Screen (1080,1920), mSize (1440,1920)
02-26 16:54:43.858: I/QCAR(2882): Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargets_setProjectionMatrix
02-26 16:54:46.541: I/System.out(2882): Cursor size 1

Upvotes: 0

Views: 1782

Answers (1)

user4003509
user4003509

Reputation:

--->Problem solved<---

My assets photo was located in an assets subfolder, so I altered code

InputStream ims = getAssets().open("25.png");

to

String filename = "My assets subfolder name/"+ "25.png";
            InputStream ims = assetManager.open(filename);

Upvotes: 1

Related Questions