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

Related Questions

My app keeps track of the state of about 1000 objects. Those objects are
In my (PHP) web app, I have a part of my site that keeps
I'm trying to figure out why my app's TCP/IP connection keeps hiccuping every 10
I have a winforms app and i want to keep track of every time
I want to keep logs of some things that people do in my app,
I have a web app built against asp.net 2.0, but keep getting the following
My app has many controls on its surface, and more are added dynamically at
An app I'm writing always crashes on a clients computer, but I don't get
My app is installed via NSIS. I want the installer to install the program
My app uses a WebRequest at certain points to get pages from itself. This

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.