Hi, I cant figure out why my program is showing null pointer exception. Plz help me...Here's the program...
public class MusicListActivity extends Activity {
List<HashMap<String, String>> songNodeDet = new ArrayList<HashMap<String,String>>();
HashMap<?,?>[] songNodeWeb;
XMLRPCClient client;
String logInSess;
ArrayList<String> paths=new ArrayList<String>();
public ListAdapter adapter ;
Object[] websongListObject;
List<SongsList> SngList=new ArrayList<SongsList>();
Runnable r;
ProgressDialog p;
ListView lv;
String s;
@Override
public void onCreate(Bundle si){
super.onCreate(si);
setContentView(R.layout.openadiuofile);
lv=(ListView)findViewById(R.id.list1);
r=new Runnable(){
public void run(){
try{
getSongs();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLRPCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Thread t=new Thread(r,"background");
t.start();
Log.e("***","process over");
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
private Runnable returnRes = new Runnable() {
@Override
public void run() {
Log.d("handler","handler");
removeDialog(0);
p.dismiss();
list();
}
};
public void list()
{ Log.d("#####","#####");
LayoutInflater inflater=getLayoutInflater();
String[] from={};
int[] n={};
adapter=new SongsAdapter(getApplicationContext(),songNodeDet,R.layout.row,from,n,inflater);
lv.setAdapter(adapter);}
private Handler handler = new Handler() {
public void handleMessage(Message msg){
Log.d("*****","handler");
removeDialog(0);
p.dismiss();
}
};
public void webObjectList(Object[] imgListObj,String logInSess) throws XMLRPCException{
songNodeWeb = new HashMap<?,?>[imgListObj.length];
if(imgListObj!=null){
Log.e("completed","completed");
for(int i=0;i<imgListObj.length;i++){ //imgListObj.length
songNodeWeb[i]=(HashMap<?,?>)imgListObj[i];
String nodeid=(String) songNodeWeb[i].get("nid");
break;
Log.e("img",i+"completed");
HashMap<String,String> nData=new HashMap<String,String>();
nData.put("nid",nodeid);
Object nodeget=client.call("node.get",logInSess,nodeid);
HashMap<?,?> imgNode=(HashMap<?,?>)nodeget;
String titleName=(String) imgNode.get("titles");
String movieName=(String) imgNode.get("album");
String singerName=(String) imgNode.get("artist");
nData.put("titles", titleName);
nData.put("album", movieName);
nData.put("artist", singerName);
Object[] imgObject=(Object[])imgNode.get("field_image");
HashMap<?,?>[] imgDetails=new HashMap<?,?>[imgObject.length];
imgDetails[0]=(HashMap<?, ?>)imgObject[0];
String path=(String) imgDetails[0].get("filepath");
if(path.contains(" ")){
path=path.replace(" ", "%20");
}
String imgPath="http://www.gorinka.com/"+path;
paths.add(imgPath);
nData.put("path", imgPath);
Log.e("my path",path);
String mime=(String)imgDetails[0].get("filemime");
nData.put("mime", mime);
SongsList songs=new SongsList(titleName,movieName,singerName,imgPath,imgPath);
SngList.add(i,songs);
songNodeDet.add(i,nData);
}
Log.e("paths values",paths.toString());
// return imgNodeDet;
handler.sendEmptyMessage(0);
}
}
public void getSongs() throws MalformedURLException, XMLRPCException
{
String ur="http://www.gorinka.com/?q=services/xmlrpc";
URL u=new URL(ur);
client = new XMLRPCClient(u);
//Connecting to the website
HashMap<?, ?> siteConn =(HashMap<?, ?>) client.call("system.connect");
// Getting initial sessio id
String initSess=(String)siteConn.get("sessid");
//Login to the site using session id
HashMap<?, ?> logInConn =(HashMap<?, ?>) client.call("user.login",initSess,"prakash","stellentsoft2009");
//Getting Login sessid
logInSess=(String)logInConn.get("sessid");
websongListObject =(Object[]) client.call("nodetype.get",logInSess,"");
webObjectList(websongListObject,logInSess);
Log.d("webObjectList","webObjectList");
runOnUiThread(returnRes);
}
}
Here's the Adapter associated...
public class SongsAdapter extends SimpleAdapter{
static List<HashMap<String,String>> songsList;
Context context;
LayoutInflater inflater;
public SongsAdapter(Context context,List<HashMap<String,String>> imgListWeb,int layout,String[] from,int[] to,LayoutInflater inflater) {
super(context,songsList,layout,from,to);
this.songsList=songsList;
this.context=context;
this.inflater=inflater;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int postition,View convertView,ViewGroup parent)throws java.lang.OutOfMemoryError{
try {
View v = ((LayoutInflater) inflater).inflate(R.layout.row,null);
ImageView images=(ImageView)v.findViewById(R.id.image);
TextView tvTitle=(TextView)v.findViewById(R.id.text1);
TextView tvAlbum=(TextView)v.findViewById(R.id.text2);
TextView tvArtist=(TextView)v.findViewById(R.id.text3);
HashMap<String,String> songsHash=songsList.get(postition);
String path=songsHash.get("path");
String title=songsHash.get("title");
String album=songsHash.get("album");
String artist=songsHash.get("artist");
String imgPath=path;
final ImageView imageView = (ImageView) v.findViewById(R.id.image);
AsyncImageLoaderv asyncImageLoader=new AsyncImageLoaderv();
Bitmap cachedImage = asyncImageLoader.loadDrawable(imgPath, new AsyncImageLoaderv.ImageCallback() {
public void imageLoaded(Bitmap imageDrawable, String imageUrl) {
imageView.setImageBitmap(imageDrawable);
}
});
imageView.setImageBitmap(cachedImage);
tvTitle.setText(title);
tvAlbum.setText(album);
tvArtist.setText(artist);
return v;
}
catch(Exception e){
Log.e("error",e.toString());
}
return null;
}
public static Bitmap loadImageFromUrl(String url) {
InputStream inputStream;Bitmap b;
try {
inputStream = (InputStream) new URL(url).getContent();
BitmapFactory.Options bpo= new BitmapFactory.Options();
bpo.inSampleSize=2;
b=BitmapFactory.decodeStream(inputStream, null,bpo );
return b;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Here is what logcat is showing...
04-23 16:02:02.211: ERROR/completed(1450): completed
04-23 16:02:02.211: ERROR/paths values(1450): []
04-23 16:02:02.211: DEBUG/*****(1450): handler
04-23 16:02:02.211: DEBUG/AndroidRuntime(1450): Shutting down VM
04-23 16:02:02.211: WARN/dalvikvm(1450): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
04-23 16:02:02.222: ERROR/AndroidRuntime(1450): Uncaught handler: thread main exiting due to uncaught exception
04-23 16:02:02.241: DEBUG/webObjectList(1450): webObjectList
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): java.lang.NullPointerException
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at com.stellent.gorinka.MusicListActivity$2.handleMessage(MusicListActivity.java:81)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at android.os.Looper.loop(Looper.java:123)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at android.app.ActivityThread.main(ActivityThread.java:4203)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at java.lang.reflect.Method.invoke(Method.java:521)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-23 16:02:02.252: ERROR/AndroidRuntime(1450): at dalvik.system.NativeStart.main(Native Method)
I have declared the getter and setter methods in a seperate claa named SongsList. Plz help me determine the problem...