last day (15 days later) » 

5:44 PM
0
A: SwipeRefreshLayout with EmptyView nullPointerException

RaghunandanYou need to have context = this; in onCreate In myListAdapter = new MyListAdapter(context, R.layout.row, monitored);// here you are using context Context is available once activity is created Line 441 is mListener.onRefresh(); Looking at the source public void setOnRefreshListener...

 
It's declared as a field above the onCreate() final Context context = this;
 
@HugoM.Zuleta Context context is declaration . Initialize context =this in onCreate. Also it need not be final.
@HugoM.Zuleta no. do it in onCreate is what i mentioned.
 
Still get the error it after following your recommendation.
 
@HugoM.Zuleta that's one mistake.
@HugoM.Zuleta you can look at the source and check the line number form stacktrace and fix the problem github.com/futuresimple/android-support-v4/blob/master/src/java/…
@HugoM.Zuleta can you post the full activity code
@HugoM.Zuleta source hints that you have not implemented OnRefreshListener in your Activity properly and this in swipeLayout.setOnRefreshListener(this); refers to Activity
 
the Activity implements OnRefreshListener and I overrode the method. It's all up there, right below the onCreate()
 
5:44 PM
I check the source
mListener = listener;
mListener is null
This points to
public void setOnRefreshListener(OnRefreshListener listener) {
mListener = listener;
}
So What else can be blamed for NPE OnRefreshListener listener
Where do the closing brace of onCreate end
 
Hold on
I'm pushing the project into github so you can see the entire activity code
Thanks again for your help
 
Kindly post it here itself
I am not going to look at githiub link
Your post should be helpful for others also
in the future
 
Oh okay. Let me copy all of it.
Yeah, I hope so.
package com.hz.noticupos;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.ExecutionException;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
 
Not all it just the relevant part related
 
lol, sorry. Give me a second.
public class MonitoredCoursesActivity extends ListActivity implements OnRefreshListener {

private SwipeRefreshLayout swipeLayout;
private ArrayList<Course> monitored;
private String lastUpdate;
private ListView myList;
private MyListAdapter myListAdapter;
Context context;
// private int freqUpdate;
// private String updateTime;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
setContentView(R.layout.activity_main);
if (loadState()==null) {
There. What I'm basically doing is parsing a HTML document, getting some data off of it, create objects with that data, objects from the class "Course", and adding them to an arraylist. I implemented my own adapter so that it modifies the row.xml with my custom values.
Do you need the adapter code or the SearchTask (where I do the HTML parsing) code?
 
5:59 PM
I am not sure but according to the source that is all i can say.
More of the same
0
Q: Exception Dispatching Input Event and Null Pointer Exception on SwipeRefreshLayout Pull down

I'm_With_StupidI have a swipe to refresh layout (part of android.support.v4 revision 19.1), and when I swipe down on the layout I can get to the point where the top part is full, but swiping down any further will cause the app to crash, and the logcat points to no specific line in my code. Since SwipeRefreshLay...

So i am right
Whys is this false swipeLayout.setRefreshing(false);
Also get rid of the other swipe refresh layout in your layout xml
The one with scrollview
 
Yeah, I saw that and linked that at the very top of my question. His answer doesn't relate to my situation since he had a viewpager
 
Well the one with upvote points to my posted answer
 
It has setRefreshing(false), because to be honest, I copied it off a tutorial. I'll look into it.
 
remove the other sipe layout in xml
the one with scrollview and textview is really not needed
 
The other swiperefresh is there because I want the app to have an EmptyView for when the list is empty. SwipeRefreshLayout can only have one direct child (it's coded that way), so that's the workaround to have an empty view
 
6:05 PM
try it with just the listview
Hey for testing remove it
Its not needed
 
Alright, I'll leave only the first one and try
 
and also you can use listview.setEmptyView
intead of the other swipe layout
for the empty case read cyrilmottier.com/2011/06/20/…
 
You're right. I'll do that. I had done it this way because I was desperate
Guess what
 
what?
 
The activity_main with two swipeRefreshLayout was the problem
 
6:13 PM
yes
 
I'll update my question and post the answer
 
If you read the link i posted the one with view pager
It does say that you need to define the listener for the other one also
In your case you had it for one
the first layout
So my answer still holds good
Your OnRefreshListener was null
Source doesn't lie
:)
 
You're awesome! That makes so much sense
 
well i updated my post
so if it helps go ahead and accept
if you feel you have a better answer post your own.
Good luck and bye
Note:
Context is available once activity is created
SO if you have the initialization before onCreate
context will be null
Activity extends context
You will need a valid context
Also final modifier is not required
since Context context; is declared as a instance variable
Sorry for the long explanation.
 
Thanks, no worries
This makes everything clearer
Check out my answer on the question
I set yours as the accepted answer, to be fair
 

last day (15 days later) »