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 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

Im not sure why, but my app all of a sudden keeps force closing
Here is my source code and it keeps force closing everytime I run it...
my application keeps force closing. But Eclipse shows no error or warnings package com.example.pkg;
Hey guys how can I make an app keep playing an mp3 after pressed
I can't find i smooth 100% working way to keep my app in the
after the phone reboot or the app force close the listener that i set
I have a strange problem. My app keeps starting in landscape mode. If I
I have an app that functions properly and does not force close or crash.
My app keeps track of the state of about 1000 objects. Those objects are
I'm tryin to create a simple app that basically is a tracker that keeps

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.