Friday, 23 August 2013

I have got a nullpointer exception

I have got a nullpointer exception

hi i have created an application in android but on running I am getting a
null pointer exception
I am giving my log cat and java class below I need a better solution to
overcome this error
08-23 10:09:57.426: E/AndroidRuntime(3373): FATAL EXCEPTION: main
08-23 10:09:57.426: E/AndroidRuntime(3373): java.lang.RuntimeException:
Unable to start
activity ComponentInfo{com.neochat/com.neochat.Friends_list}:
java.lang.NullPointerException
08-23 10:09:57.426: E/AndroidRuntime(3373): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-23 10:09:57.426: E/AndroidRuntime(3373): at
android.app.ActivityThread.startActivityNow(ActivityThread.java:2023)
08-23 10:09:57.426: E/AndroidRuntime(3373): at
android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
Here is my java class
public class Friends_list extends Activity implements
OnItemClickListener{
private ArrayList<String> results = new ArrayList<String>();
private SQLiteDatabase newDB;
LoginDataBaseAdapter loginDataBaseAdapter ;
ListView listview;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends);
listview=(ListView)findViewById(R.id.listview);
context=this;
loginDataBaseAdapter.getfriends();
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3)
{
Intent in2=new
Intent(Friends_list.this,InboxActivity.class);
startActivity(in2);
}
}
I am giving my getFriends() function below
public List<String>getfriends(){
List<String> FriendList=new ArrayList<String>();
String selectQuery="select * from UserDetails";
db=dbHelper.getWritableDatabase();
Cursor cursor=db.rawQuery(selectQuery, null);
while(cursor.moveToNext()){
FriendList.add(cursor.getString(1));
}
return FriendList;
}
I want to display the contents of the table in the database to a listview
in my activity can anybody help me

No comments:

Post a Comment