Monday, May 2, 2016

[Android][Resolved] Cannot resolve method 'setArguments (android.os.Bundle)'


Got this error during following the Android official tutorial about Fragment. There is 2 files related to this problem : (MainActivity.java & HeadlinesFragment.java)

MainActivity.java


HeadlinesFragment.java

Since the line "firstFragment.setArguments(getIntent().getExtras());" with error is calling method named setArguments() in firstFragement (Type HeadlinesFragment). However, there is no method with this name in HeadlinesFragment class and make "Cannot resolve method setArguments" message appear.

To solve that, you needed to extends a class which's including the method "setArguments", for example, class Fragment and ListFragment, you have to check that in Android official doc.

For example, Class Fragment is including a setArguments method:

http://developer.android.com/reference/android/support/v4/app/Fragment.html#setArguments(android.os.Bundle)

ListFragment is another class with setArguments method , after extends that in Class HeadlinesFragment. The problem solved.


Reference:

http://developer.android.com/training/basics/fragments/fragment-ui.html
http://stackoverflow.com/questions/34640813/fragmentactivity-setarguments-cannot-resolve
http://developer.android.com/reference/android/support/v4/app/Fragment.html#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)

No comments :

Post a Comment