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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:02:54+00:00 2026-06-07T03:02:54+00:00

Can’t start new activity. Got problem in onClickListener. I post a code an errors.

  • 0

Can’t start new activity. Got problem in onClickListener.

I post a code an errors. Have not any idea why I got error in this line.

I think it can be not initialized variable Button b, but it’s initialized!

Help, plz.

Code:

public class newItem extends Activity {
    private EditText Quantity;
    private EditText Weight;
    private EditText Price;
    private EditText Title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_list);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        Button b = (Button) findViewById(R.id.ok_but);
        Quantity = (EditText) findViewById(R.id.Quantity);
        Weight = (EditText) findViewById(R.id.Weight);
        Price = (EditText) findViewById(R.id.Price);
        Title = (EditText) findViewById(R.id.Title);

        b.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                i.putExtra("Quantity", Quantity.getText().toString());
                i.putExtra("Weight", Weight.getText().toString());
                i.putExtra("Price", Price.getText().toString());
                i.putExtra("Title", Title.getText().toString());
                setResult(RESULT_OK, i);
                Log.i("palval", "setResult(RESULT_OK, i); newItem");
                finish();
            }
        });
    }
}

Error:

07-08 17:26:42.402: E/AndroidRuntime(31626): FATAL EXCEPTION: main
07-08 17:26:42.402: E/AndroidRuntime(31626): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ashopping_list/com.example.ashopping_list.newItem}: java.lang.NullPointerException
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.os.Looper.loop(Looper.java:154)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.ActivityThread.main(ActivityThread.java:4945)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at java.lang.reflect.Method.invokeNative(Native Method)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at java.lang.reflect.Method.invoke(Method.java:511)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at dalvik.system.NativeStart.main(Native Method)
07-08 17:26:42.402: E/AndroidRuntime(31626): Caused by: java.lang.NullPointerException
07-08 17:26:42.402: E/AndroidRuntime(31626):    at com.example.ashopping_list.newItem.onCreate(newItem.java:32)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.Activity.performCreate(Activity.java:4531)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
07-08 17:26:42.402: E/AndroidRuntime(31626):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)

Manifest:

    <activity
        android:name=".newItem"
        android:label="@string/title_activity_main"
        android:windowSoftInputMode="stateAlwaysVisible" >
    </activity>

Err here:

b.setOnClickListener(new OnClickListener() {
  • 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-07T03:02:56+00:00Added an answer on June 7, 2026 at 3:02 am

    Try to use

    implements View.OnClickListener
    

    or try to use Listener as anonymous class and then tell me if it works.

    Note: class names should start with uppercase and you should respect it.

    Update:

    So problem is elsewhere, make sure that your ID is correct! and belongs to Button.

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

Sidebar

Related Questions

Can i get the source code for a WAMP stack installer somewhere? Any help
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can't figure out how to do this in a pretty way : I have
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
Can any one tell me clearly why ? Reading is simple in ArrayList,( we
Can you have submenus with the top level set to checkable in WPF? I
Can we close all known/unknown connections to database with the code? I'm using Access

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.