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

  • Home
  • SEARCH
  • 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 884549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:46:04+00:00 2026-05-15T12:46:04+00:00

my app keeps force closing before it starts… eclipse returns no errors in my

  • 0

my app keeps force closing before it starts… eclipse returns no errors in my code and my xml is good. can anybody give me some insight?

package com.mhe.test.scan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class main extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button myScanButton = (Button) findViewById(R.id.myScanButton);         
          myScanButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
                startActivityForResult(intent, 0);

               }
            });
    }


    EditText totalbox = (EditText) findViewById(R.id.totalbox);
        public void onActivityResult(int requestCode, int resultCode, Intent intent) {
            if (requestCode == 0) {
                if (resultCode == RESULT_OK) {
                    String contents = intent.getStringExtra("SCAN_RESULT");
                    // Handle successful scan
                    totalbox.setText(contents);
                } else if (resultCode == RESULT_CANCELED) {
                    // Handle cancel
                    totalbox.setText("@string/bummer");
                }



            }      
         }
    }

essentially it is supposed to call zxing Barcode Scanner to scan a barcode on a button click and return the result into an EditText field… i’m a total newbie at this…

  • 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-15T12:46:05+00:00Added an answer on May 15, 2026 at 12:46 pm

    The line:

    EditText totalbox = (EditText) findViewById(R.id.totalbox);
    

    Is not in the OnCreate method, so its trying to initialize the totalbox before the activity is created, probably causing the crash

    Try this instead:

    package com.mhe.test.scan;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class main extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button myScanButton = (Button) findViewById(R.id.myScanButton); 
        // set the totalbox in the onCreate
        totalbox = (EditText) findViewById(R.id.totalbox);        
        myScanButton.setOnClickListener(new Button.OnClickListener() {
          public void onClick(View v) {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
            startActivityForResult(intent, 0);
          }
        });
      }
    
      public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
          if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            // Handle successful scan
            // check that it exists, just in case
            if ( totalbox != null )
              totalbox.setText(contents);
          } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
            // check that it exists, just in case
            if ( totalbox != null )
              totalbox.setText("@string/bummer");
          }
        }      
      }
    
      private EditText totalbox;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Don't bother with optional parameters or some collection of parameters,… May 16, 2026 at 10:12 am
  • Editorial Team
    Editorial Team added an answer Nope. That is not possible. You cannot access client system… May 16, 2026 at 10:12 am
  • Editorial Team
    Editorial Team added an answer It is safe, but foo needs to be final (otherwise… May 16, 2026 at 10:12 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

sometimes i use debug code to alert something in javascript (for example, matching something
I seem to have an app on my Dev server that has lots of
I'm building an iPhone app, and my app copies a bunch of resources to
I pass text strings from a configuration file into my Flex app, one of
I'm battleing with extending a TextView for my Android app. I'd like to create
I’m trying to access a certain bit of the registry however it keeps returning
I am trying to sign an application with my new code signing key, but
I've got an app I'm working on where we handle a LOT of images
I have an app that works perfectly on my local machine and am deploying
Do all apps crash if you load them in the simulator - hit the

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.