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 5977707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:24:34+00:00 2026-05-22T21:24:34+00:00

I am invoking the native camera using intent to capture images and in the

  • 0

I am invoking the native camera using intent to capture images and in the activity result i am trying to provide a caption for the image captured and adding it to a list, but i am not successful in doing so i get an error when i add the item to the list. From the device the application force closes and am not able to figure out the error. Could someone kindly suggest me the correct way of adding the element to the List. Should it be added to the adapter or the underlying ArrayList? Kindly help me with this.

My code is as below:

public class AttachmentsActivity extends ListActivity {

private AttachmentListAdapter m_adapter;
private ArrayList<MediaData> m_orders = null;
StringBuffer nameBuffer;
private String captureDateTime;
private Uri uri;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    m_orders = new ArrayList<MediaData>();
    Enumeration<MediaData> enumeration = DashboardManager.getInstance()
            .getAttachmentList().elements();
    while (enumeration.hasMoreElements()) {
        m_orders.add((MediaData) enumeration.nextElement());
    }

    this.m_adapter = new AttachmentListAdapter(this,
            android.R.layout.simple_list_item_1, m_orders);
    setListAdapter(this.m_adapter);
    this.m_adapter.notifyDataSetChanged();
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    menu.removeGroup(1);
    if (DashboardManager.getInstance().isEnableCamera()) {
        menu.add(1, 1, Menu.NONE, "Camera");
    }
    if (DashboardManager.getInstance().isEnableAudio()) {
        menu.add(1, 2, Menu.NONE, "Audio");
    }

    return true;
}

private class AttachmentListAdapter extends ArrayAdapter<MediaData> {

    private ArrayList<MediaData> items;
    private LayoutInflater mInflater;
    private Bitmap high;
    private Bitmap medium;
    private Bitmap low;
    private LinearLayout linearLayout;
    private TextView[] textViews;
    private Context context;
    private Vector tableHeaders;
    private int width;
    private StringBuffer firstLine;



    public AttachmentListAdapter(Context context, int textViewResourceId,
            ArrayList<MediaData> items) {
        super(context, textViewResourceId, items);
        this.context = context;
        System.out.println("Inside NotificationListAdapter");
        System.out.println(items);
        this.items = items;
        firstLine = new StringBuffer();
        mInflater = LayoutInflater.from(context);
        Display display = getWindowManager().getDefaultDisplay();

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MediaData mediaData = items.get(position);
        ViewHolder holder = null;
        if (mediaData != null) {
            if (convertView == null) {
                holder = new ViewHolder();
                // holder.content = (TextView) mInflater.inflate(
                // R.layout.column, null);
                holder.content = new TextView(context);
                holder.content.setGravity(Gravity.CENTER_VERTICAL);
                holder.content.setHeight(25);
                convertView = mInflater.inflate(R.layout.table_row, null);
                linearLayout = (LinearLayout) convertView
                        .findViewById(R.id.linearLayout);

                linearLayout.addView(holder.content);

            }
            firstLine.delete(0, firstLine.length());
            firstLine.append(mediaData.getType()).append(" ")
                    .append(mediaData.toString());

            holder.content.setText(firstLine.toString());
        }

        return linearLayout;
    }

}

static class ViewHolder {
    TextView content;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {

    case 1:
        nameBuffer = new StringBuffer();
        if (DashboardManager.getInstance().getWaterMarkingText().length() > 0) {
            nameBuffer.append(
                    DashboardManager.getInstance().getWaterMarkingText())
                    .append("_");
        }

        captureDateTime = Calander.getSubmitDateTime(new Date());
        nameBuffer
                .append(captureDateTime)
                .append("_")
                .append(MobileBaseService.getInstance()
                        .getApplicationUser().getUserId()).append(".jpg");

        String dirString = "/sdcard/pravaa/";
        File dir = new File(dirString);
        if(!dir.exists()) dir.mkdir();
        File attachment=new File(dirString+nameBuffer.toString());
        uri=Uri.fromFile(attachment);
        System.out.println("URI:" + attachment.toURI());
        int resultCode = 1337;

        startActivityForResult(AttachmentUtility.getCameraIntent(uri),
            resultCode);


    }
    return true;
}



protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case 1337:

                     // TODO Auto-generated method stub String
                     String dirString="/sdcard/pravaa/"; //Toast

                      File attachment=new File(dirString+nameBuffer.toString());


                      if(attachment.exists()){ 
                          try { 
                      FileInputStream fis;
                      fis = new FileInputStream(attachment);
                      ByteArrayOutputStream baos = new ByteArrayOutputStream();

                      Bitmap bi = BitmapFactory.decodeStream(fis);
                      bi.compress(CompressFormat.JPEG, 100, baos);
                      byte[]attData = baos.toByteArray();
                      fis.close();
                      if (attData.length>0) {
                                MediaData mediaData = new MediaData();
                                mediaData.setAttachmentUri(uri);
                                mediaData.setType(ApplicationStore.MEDIA_TYPE_IMAGE);
                                mediaData.setData(attData);
                                mediaData.setNewAttachment(true);
                                mediaData.setNote("");
                                mediaData.setTransactionId(MobileBaseService.getInstance().getNextTransactionId());
                                mediaData.setCaptureDataTime(captureDateTime);
                                mediaData.setCaption(mediaData.getCaptureDataTime() + "_" + MobileBaseService.getInstance().getApplicationUser().getUserId());
                                mediaData.setNumber(nameBuffer.toString());

                                if (DashboardManager.getInstance().isEnableGps() && ApplicationManager.getInstance().isGpsEnabled()) {
                                    mediaData.setGpsEnabled(true);
                                    Location location= ApplicationManager.getInstance().getLocation();

                                    if (location != null) {

                                        mediaData.getGpsData().setLattitude(location.getLatitude());
                                        mediaData.getGpsData().setLongitude(location.getLongitude());
                                        mediaData.getGpsData().setAltidude(location.getAltitude());
                                        mediaData.getGpsData().setAccuracy("Y");
                                        mediaData.getGpsData().setDateTime(Calander.getSubmitDateTime(new Date()));
                                    } else {
                                     //   ApplicationManager.getInstance().Log(Level.TRACE, "Could not obtain GPS for Attachment " + mediaData.getNumber());
                                        mediaData.getGpsData().setLattitude(0);
                                        mediaData.getGpsData().setLongitude(0);
                                        mediaData.getGpsData().setAltidude(0);
                                        mediaData.getGpsData().setAccuracy("N");
                                        mediaData.getGpsData().setDateTime("");
                                    }
                                } else {
                                    mediaData.getGpsData().setLattitude(0);
                                    mediaData.getGpsData().setLongitude(0);
                                    mediaData.getGpsData().setAltidude(0);
                                    mediaData.getGpsData().setAccuracy("N");
                                    mediaData.getGpsData().setDateTime(Calander.getSubmitDateTime(new Date()));
                                }
                                    **//Commenting this line of code does not cause the crash**
                                m_adapter.add(mediaData);


                      }
                      } catch (FileNotFoundException e) {
                     //e.printStackTrace();
                     } catch (IOException e) {

                    // TODO Auto-generated catch block
                    // e.printStackTrace();
                     }catch (Exception e) {

                     }
                     }
            break;
        }
    }
}
}

I get an error when the following gets called :
m_adapter.add(mediaData); (line no 149) and my stack trace is as below:

E/AndroidRuntime( 1367): java.lang.NullPointerException
E/AndroidRuntime( 1367):        at com.pravaa.dashboard.ui.components.Attachment
sActivity$AttachmentListAdapter.getView(AttachmentsActivity.java:149)
E/AndroidRuntime( 1367):        at android.widget.AbsListView.obtainView(AbsList
View.java:1427)
E/AndroidRuntime( 1367):        at android.widget.ListView.makeAndAddView(ListVi
ew.java:1802)
E/AndroidRuntime( 1367):        at android.widget.ListView.fillSpecific(ListView
.java:1347)
E/AndroidRuntime( 1367):        at android.widget.ListView.layoutChildren(ListVi
ew.java:1633)
E/AndroidRuntime( 1367):        at android.widget.AbsListView.onLayout(AbsListVi
ew.java:1280)
E/AndroidRuntime( 1367):        at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 1367):        at android.widget.FrameLayout.onLayout(FrameLayo
ut.java:333)
E/AndroidRuntime( 1367):        at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 1367):        at android.widget.LinearLayout.setChildFrame(Lin
earLayout.java:1249)
E/AndroidRuntime( 1367):        at android.widget.LinearLayout.layoutVertical(Li
nearLayout.java:1125)
E/AndroidRuntime( 1367):        at android.widget.LinearLayout.onLayout(LinearLa
yout.java:1042)
E/AndroidRuntime( 1367):        at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 1367):        at android.widget.FrameLayout.onLayout(FrameLayo
ut.java:333)
E/AndroidRuntime( 1367):        at android.view.View.layout(View.java:7035)
E/AndroidRuntime( 1367):        at android.view.ViewRoot.performTraversals(ViewR
oot.java:1045)
E/AndroidRuntime( 1367):        at android.view.ViewRoot.handleMessage(ViewRoot.
java:1727)
E/AndroidRuntime( 1367):        at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime( 1367):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 1367):        at android.app.ActivityThread.main(ActivityThrea
d.java:4633)
E/AndroidRuntime( 1367):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 1367):        at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime( 1367):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:858)
E/AndroidRuntime( 1367):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:616)
E/AndroidRuntime( 1367):        at dalvik.system.NativeStart.main(Native Method)

The error occurs at the following line holder.content.setText(firstLine.toString()); in the getView() method of AttachmentListAdapter.
Kindly help me with this. Thanks in advance.

  • 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-05-22T21:24:35+00:00Added an answer on May 22, 2026 at 9:24 pm

    You do not assign holder a value in case that the convertView is not null. To use this “holder”-technique correctly, save the holder within the convertView (as tag), and retrieve it in case the convertView is not null (it is explained in this video quite nicely, have a look at it!).

       ViewHolder holder = null;
        if (mediaData != null) {
            if (convertView == null) {
                holder = new ViewHolder();
                // holder.content = (TextView) mInflater.inflate(
                // R.layout.column, null);
                holder.content = new TextView(context);
                holder.content.setGravity(Gravity.CENTER_VERTICAL);
                holder.content.setHeight(25);
                convertView = mInflater.inflate(R.layout.table_row, null);
                convertView.setTag(holder);
                linearLayout = (LinearLayout) convertView
                        .findViewById(R.id.linearLayout);
    
                linearLayout.addView(holder.content);
    
            } else {
                holder = convertView.getTag();
            }
            firstLine.delete(0, firstLine.length());
            firstLine.append(mediaData.getType()).append(" ")
                    .append(mediaData.toString());
    
            holder.content.setText(firstLine.toString());
        }
    

    There are also some other strange things going on (e.g., why is linearLayout a member variable), where you should have a look at.

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

Sidebar

Related Questions

I am invoking camera from my application. i want to remove few menu items
We have a native app that we can access via JNI->DLL or by invoking
Is invoking destroy (native method) enough, or should I take additional measures like manually
I am trying to invoke the native application for MEDIA content, so I can
I am trying to include ngen to my installer using this article . I
I am trying to convert a jbyteArray to native c string (char*) in jni?
Possible Duplicate: When does invoking a member function on a null instance result in
I'm invoking Video Recorder as below. Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE); startActivityForResult(intent, REQUEST_VIDEO_CAPTURED); Is
I have a strange problem with native Ajax request invoking. I am creating the
When invoking a WCF service asynchronous there seems to be two ways it can

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.