kartik trivedi
kartik trivedi

Reputation: 1055

error while starting another activity

i am starting new activity from current activity but some how before starting activity i am getting Null Pointer exception. and startActivity() from source activity calls sucessfully. I am getting Null Pointer exception. the following is code.

Intent intent = new Intent(PdfFileSelectActivity.this, PdfViewerActivity.class)
        .putExtra(EXTRA_PDFFILENAME, pdffilename)
        .putExtra(EXTRA_USENIO, useNIO);

i checked intenet pdffilename variable and they are not null. and the following is declaration in manifest file.

Hope to hear soon.

Upvotes: 0

Views: 205

Answers (2)

Abhinav Singh Maurya
Abhinav Singh Maurya

Reputation: 3313

you must specify the name of both the activity in androidmanifest.xml file eg:

`<activity android:name=".PdfFileSelectActivity"/>

this activity is already defined in .xml file but you have also to define this activity

<activity android:name=".PdfViewerActivity"/>

after

<application/> tag`

Upvotes: 0

Mathias Conradt
Mathias Conradt

Reputation: 28665

This issue has been resolved via skype session - the problem was that the intent extras were read outside the onCreate, where the boolean useBIO was declared as class variable - but at that point the intent extras are not available yet.

boolean useNIO = getIntent().getBooleanExtra(PdfFileSelectActivity.EXTRA_USENIO, PdfFileSelectActivity.DEFAULTUSENIO);

had to be moved inside onCreate.

Upvotes: 2

Related Questions