Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:05:21+00:00 2026-06-06T17:05:21+00:00

I have a tab view which has a listview in one of these tabs.

  • 0

I have a tab view which has a listview in one of these tabs. This listview displays the name of files which contain images. When a name is clicked, I would like for it to display the image. I have tried numerous techniques but still keep running into errors and I have no idea what to do. If you could provide any help or information it will be greatly appreciated.

Here’s the code:

package com.example.classname;


import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import android.app.ListActivity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class RecordsActivityTwo extends ListActivity {

private static String f2;
private static String fileNames[];
final File root = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/classname/Camera");
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    //ListDir(root);
    if (root.isDirectory()){
        //lists the file names into an array
        fileNames = root.list();


        //loop used to remove the jpg suffix on file names
        int cntr = 0;
        while (cntr <= (fileNames.length - 1)) {
            fileNames[cntr] = fileNames[cntr].replace(".jpg", "");
            cntr = cntr + 1;
        }

    } else {
        Toast.makeText(this, "Did not get into the directory", Toast.LENGTH_LONG).show();
    }

    setListAdapter(new ArrayAdapter<String>(this, R.layout.recordsactivitytwo, fileNames));






     final ListView lv = getListView();
     lv.setTextFilterEnabled(true);
     lv.setClickable(true);

     lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

     public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3){

         Object o = lv.getItemAtPosition(position);
         f2 = o.toString() + ".jpg";
         Toast.makeText(getApplicationContext(), f2, Toast.LENGTH_LONG);
         //now write the code for loading the file
         //object o should be the file, so i need to load object o
         //the following code deals with opening the clicked file and displaying it
         imageViewMethod(f2);
         //Intent i = new Intent(getApplicationContext(), ImageViewActivity.class);
         //i.putExtra("text", f2);
         //startActivity(i);
         //ImageView iv = (ImageView)findViewById(R.id.imageviewreader);
         //iv.setImageBitmap(BitmapFactory.decodeFile(f2)); //displays the image from the file to the image view
     }
     });


}

public void imageViewMethod(String file){
    Logger log = Logger.getLogger("com.example.classname");

    try {
    File fileName = new File(root, file);
    String dirFileName = fileName.toString();
    Toast.makeText(getApplicationContext(), dirFileName, Toast.LENGTH_LONG).show();
    ImageView iv = (ImageView)findViewById(R.id.imageviewreader);
    iv.setImageBitmap(BitmapFactory.decodeFile(dirFileName));
    super.setContentView(iv);
    }catch(Exception e){
        Toast.makeText(getApplicationContext(), "Hit Exception", Toast.LENGTH_LONG).show();
        log.log(Level.SEVERE, "uncaught exception", e);
    }
}

}

And here is the logcat output:

06-30 15:59:17.406: E/com.example.ufohunter(569): uncaught exception
06-30 15:59:17.406: E/com.example.ufohunter(569): java.lang.NullPointerException
06-30 15:59:17.406: E/com.example.ufohunter(569):   at com.example.ufohunter.RecordsActivityTwo.imageViewMethod(RecordsActivityTwo.java:93)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at com.example.ufohunter.RecordsActivityTwo$1.onItemClick(RecordsActivityTwo.java:73)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.widget.AdapterView.performItemClick(AdapterView.java:284)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.widget.ListView.performItemClick(ListView.java:3513)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.os.Handler.handleCallback(Handler.java:587)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.os.Handler.dispatchMessage(Handler.java:92)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.os.Looper.loop(Looper.java:130)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at android.app.ActivityThread.main(ActivityThread.java:3683)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at java.lang.reflect.Method.invokeNative(Native Method)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at java.lang.reflect.Method.invoke(Method.java:507)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-30 15:59:17.406: E/com.example.ufohunter(569):   at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:05:23+00:00Added an answer on June 6, 2026 at 5:05 pm

    try to debug in order to see in which phase something went wrong . it seem you get a null pointer exception .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a TabActivity which has 4 tabs, within one of the tab's
I have an Android tab layout with three tabs, one of which has a
I have an app which has split view inside a tab bar, and these
I have one tabview which contain two different tab(subject and chapter) and i need
I have a UITabBar application, which has three tabs. The first tab has a
I have an application which has 7 tabs with associated views and view controllers.
I have a root view controller which has few buttons. On click of these
I have 3 subviews in a UITabBarController. The first tab's view has objects which
I have tab bar in which one tab has a UINavigationController that is assigned
I have an app which has a UITabBarController, and when different tabs are pressed,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.