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

The Archive Base Latest Questions

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

EDIT i updated the code to reflect changes suggested in both answers, unfortunately, now

  • 0

EDIT i updated the code to reflect changes suggested in both answers, unfortunately, now my app force closes. the error is listed at the bottom

this is my camera/picture class in its entirety (except for imports) this class is supposed to take a picture, display it to the screen, and let another class have the string path of the picture for use as an attachment.
it takes the picture fine, it emails the picture fine, but i cannot figure out how to make it display the picture after its taken. i know there is some sloppy code in there (like in the the onActivityResult) but everything except

Bitmap bm = BitmapFactory.decodeFile(image_string);
imageview.setImageBitmap(bm);

works great, so I am very interested in finding a solution. any other advice you have on how to clean this up would also be more than welcome, this was just sort of hobbled together from multiple different sources.

public class LooksLike extends Activity
    {       
    Button camera;
    Intent intent;
    static String image_string;
    ImageView imageview;
    public void onCreate (Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lookslike);
        camera = (Button) findViewById(R.id.camera);
        imageview = (ImageView) findViewById(R.id.debris_view);
        camera.setOnClickListener(new View.OnClickListener()
            {
            public void onClick(View v)
                {
                takePhoto();
                }
            });
        }

    public void takePhoto()
        {
        intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(this)) ); 
        startActivityForResult(intent, 1);
        Bitmap bm = BitmapFactory.decodeFile(image_string);
        imageview.setImageBitmap(bm);
        }

    private File getTempFile(Context context)
        {
        File path = new File(Environment.getExternalStorageDirectory(), context.getPackageName() );
        if(!path.exists())
            path.mkdir();
        return new File(path, "debris.jpg");
        }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
    if (resultCode == RESULT_OK)
        {
        switch(requestCode)
            {
            case 1:
            final File file = getTempFile(this);
            try
                {
                Media.getBitmap(getContentResolver(), Uri.fromFile(file) );
                image_string = Uri.fromFile(file).toString();
                Bitmap bm = Bitmap.createScaledBitmap(
                    BitmapFactory.decodeFile(image_string),
                    getResources().getDisplayMetrics().widthPixels,
                    getResources().getDisplayMetrics().heightPixels, 
                    true);
                imageview = (ImageView) findViewById(R.id.debris_view);
              imageview.setImageBitmap(bm);
                }
            catch (FileNotFoundException e)
                {
                Toast.makeText(getApplicationContext(), "file not found exception", Toast.LENGTH_SHORT).show();
                }
            catch (IOException e)
                {
                Toast.makeText(getApplicationContext(), "ioexception", Toast.LENGTH_SHORT).show();
                }
            break;
            }
        }
    }
}

also, here is my xml file:

<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView  
        android:id="@+id/debris_view"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/icon"
        />
    <Button
        android:id="@+id/camera"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dip"
        android:layout_gravity="center_horizontal|bottom"
        android:padding="12dip"
        android:background="#AA000000"
        android:textColor="#ffffffff"
        android:text="would you like to take a new debris picture?"
        />
</merge>
  • 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:03:33+00:00Added an answer on May 22, 2026 at 9:03 pm

    You need move these 2 lines into onActivityResult():

    case 1:
        final File file = getTempFile(this);
        try {
            Media.getBitmap(getContentResolver(), Uri.fromFile(file) );
            image_string = Uri.fromFile(file).toString();
            Bitmap bm = BitmapFactory.decodeFile(image_string);
            imageview.setImageBitmap(bm);
        } catch (FileNotFoundException e) {
            ...
    

    Code in takePhoto() will be executed immediately after startActivityForResult() (i.e. it will not wait finishing called activity). Processing result must be done in onActivityResult().

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

Sidebar

Related Questions

Edit: Updated code. Now works well enough. Foreword. I am an OpenGL newb tasked
EDIT: Updated code to better reflect my problem this code returns 9 strings to
Updated question to reflect answers and my research Thanks casablanca and wallyk for answering.
EDIT Updated code with solution I need to transcode amr to mp3, so i
EDIT: Updated code with new Pastebin link but it's still stopping at the info->citizens[x]->name
EDIT: Updated with suggestions from Bill Karwin below. Still very slow. I'm trying to
See updated input and output data at Edit-1. What I am trying to accomplish
In the sample code, the line with the 'error comment' gives the following the
Dynamically I want to edit/update hosts(etc/hosts) file to add domain. To edit hosts(etc/hosts) file
Is it possible to edit and update a GridView cell without using <asp:TemplateField> and/or

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.