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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:01:03+00:00 2026-06-17T18:01:03+00:00

This is my MainActivity.java I used // to mark as not using on some

  • 0

This is my MainActivity.java
I used // to mark as not using on some lines and found that the line start with int t =
Is the problem that make the application to crash and force closing.

package com.example.camera_test;

import android.os.Build;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.hardware.Camera;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {

    private static final int CAMERA_PIC_REQUEST = 1337; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.button1);

        button.setOnClickListener(new OnClickListener()
        {
        @SuppressLint("NewApi") @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );

            startActivityForResult( intent, CAMERA_PIC_REQUEST );
        }
        });


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    @SuppressLint("NewApi") protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == CAMERA_PIC_REQUEST) {  
        // do something
            Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
            int t = thumbnail.getByteCount();
            TextView age = (TextView) findViewById(R.id.textView1);
            age.setText(Integer.toString(t));
            ImageView image = (ImageView) findViewById(R.id.imageView1);
            image.setImageBitmap(thumbnail);
        }  
       }  
}

I added a button when I click on it it will open the camera on my device after I take a photo it will show the photo I took on a small window. It’s working.

Then I added this 3 lines:

int t = thumbnail.getByteCount();
TextView age = (TextView) findViewById(R.id.textView1);
age.setText(Integer.toString(t));

I wanted to show also the ByteCount of the image on screen in my device.

Once I add the line: int t = thumbnail.getByteCount(); there was an error so I did automatic fix and it added @SuppressLint(“NewApi”)

Then I marked with // this 3 lines once I unmarked and used the line int t = thumbnail.getByteCount(); so after I took a photo it crashed and told me it need to force close.

Why does it crash on this line ?

This is the file activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="45dp"
        android:layout_marginTop="62dp"
        android:text="Activate The Camera" />
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</RelativeLayout>
  1. I can’t figure out why it crash with the int t line.

  2. I added a breakpoint on the int t line but it never stop there and never stop anywhere on my application when I add a breakpoint why ?

  • 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-17T18:01:04+00:00Added an answer on June 17, 2026 at 6:01 pm

    The getByteCount() is available from API level 12 (android 3.1+).
    Are you sure you are building/running this version or above?

    Also please add LogCat in the feature, much easier to find the error.

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

Sidebar

Related Questions

I have an activity ( MainActivity.java ) in which content view is like this
I have this situation where i have to start an activity from my mainActivity.
Instead of using images like in this example I found from Android Developer Site
Iam using jtwitter library to authorize my app with Twitter. I used this http://marakana.com/forums/android/examples/312.html
I am using one MainActivity and another .java which includes a class. I want
I have an application project with source files: androidsrc/MainActivity.java androidsrc/ClientSession.java I get this error
This is my static inner class for creating an AlertDialog inside my MainActivity class:
Hello I want to get Accurate location so that i have used following link
I have developed some reusable android component which is basically a class . This
HI Am working for the application using tabs through entire app.In that one particular

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.