Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting Nullpointer exception when i try to call Fragment

 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my manifext file



this is viewer activity



this is 1st fragment


this is 2nd fragment



this is activity to open pdf files




when i run this app it gives me below error



but if i run only one fragment if my viewpager activity it doesn't give me an error,


 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where's the stack trace of the NPE? Or did you mean to say "IllegalArgumentException"?

MyFragment and MyFragment2 look similar; tell us in words how they are similar, and how they differ.

What is MainActivity for? You should never interfere with Android's lifecycle management by instantiating activities. Delete it.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyFragment and MyFragment2 are two pages of viewpager .It loads the two different pdf files.
withing each fragment i need to view different pdf files.

i used Mainactivity to open pdf files(Used Pdfviewer.jar).I put below code in MainActivity as it gives error when i put it on the Fragment.



SimpleReaderFactory.createSimpleViewer(this, m_listener)

here "this" requires Activity,when i put it inside fragment it gives error.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Where's the stack trace of the NPE? Or did you mean to say "IllegalArgumentException"?


If you want to get help you really need to pay attention to what people ask of you.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently there is no NPE ULF.It resolved now.now i am getting below exception only.But if i call only one fragment it doesn't give me any exception and it display the pdf file(WHether its fragment or fragment2).but if there is two fragment are there it gives me below exception
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That stack trace looked identical to the one you posted before, so I have deleted it. Please don't post the same stuff more than once.

The reason I asked about the NPE is because you mentioned an NPE in the title of this topic. It is confusing if you then post the stack trace of some other exception, which apparently has nothing to do with your question. Please be more careful in the future.

I note that both fragments have different layouts, and that the exception seems to have to do with layouts. So post the layout XML of both fragment classes.

This also begs the question: why do you have two fragment classes, and why do they have different layouts?
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
myfragment_layout.xml







myfragment2_layout.xml


i used two fragments as i need to pageviewer.i need to go other fragment whne user swipe.but i am getting above exception when i used 2nd fragment
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i used two fragments as i need to pageviewer.i need to go other fragment whne user swipe.

I understand that you need multiple fragments, but my question was why you were using two fragment classes? The normal approach is to use the same class for all fragments. You want all fragments to be the same, just showing different PDFs, no? That would call for a single fragment class.
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok ulf,i will try to use one fragment class.by the way can you please help to find the exception mentioned above
 
sam liya
Ranch Hand
Posts: 1243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried without pdf file,then pageviwer works fine and gives me page by page. below is the code.

main class



fragment1 class



fragment1 layout file




fragment2 class



fragment2 layout file





manifest file



this is working fine,when i swipe it goes to next fragment.but when i add pdf fiel open to each fragment it gives me above error. is i am calling pdf open in wrong lifecycle methos or is there any other place call that method?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic