开发者

NullPointerException error

Logcat

08-17 06:37:22.264: ERROR/AndroidRuntime(1090): java.lang.RuntimeException: Unable to start activity ComponentInfo{one.two/one.two.Booking}: java.lang.NullPointerException
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.os.Looper.loop(Looper.java:123)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.ActivityThread.main(ActivityThread.java:3948)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at java.lang.reflect.Method.invoke(Method.java:521)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at开发者_高级运维 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at dalvik.system.NativeStart.main(Native Method)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090): Caused by: java.lang.NullPointerException
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at one.two.Booking.onCreate(Booking.java:50)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-17 06:37:22.264: ERROR/AndroidRuntime(1090):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)

Booking.java

public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        db = new DBAdapter(this);
        this.setContentView(R.layout.booking);
        txtArrivalTime = (TextView) findViewById(R.id.txtArrivalTime); // Member assignment
        txtFerry = (TextView) findViewById(R.id.txtFerry);
        txtStatus = (TextView) findViewById(R.id.txtStatus);
        txtDestination = (TextView) findViewById(R.id.txtDestination);
        colourSpinner = (Spinner) findViewById(R.id.myspinner); // Member assignment
        Button btnBook = (Button) findViewById(R.id.btnBook);
        db.open();
        fillData();
        db.close();
        colourSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
        b = this.getIntent().getExtras();
        s = b.getString("DEFAULTTEXT");      

        btnBook.setOnClickListener(new MyOnClickListener());


    }

Line 50 is s = b.getString("DEFAULTTEXT");

Thank you.


Instead of this:

b = this.getIntent().getExtras();
s = b.getString("DEFAULTTEXT"); 

Use getStringExtra(String)

s = this.getIntent().getStringExtra("DEFAULTTEXT");

The bundle you get from getExtras() is null, hence the exception

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜