logact
05-04 17:53:15.820: E/AndroidRuntime(7709): FATAL EXCEPTION: main
05-04 17:53:15.820: E/AndroidRuntime(7709): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.registerscreen/com.example.registerscreen.FriendListActivity}: java.lang.NullPointerException
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.ActivityThread.access$500(ActivityThread.java:122)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.os.Looper.loop(Looper.java:132)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.ActivityThread.main(ActivityThread.java:4123)
05-04 17:53:15.820: E/AndroidRuntime(7709): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 17:53:15.820: E/AndroidRuntime(7709): at java.lang.reflect.Method.invoke(Method.java:491)
05-04 17:53:15.820: E/AndroidRuntime(7709): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
05-04 17:53:15.820: E/AndroidRuntime(7709): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
05-04 17:53:15.820: E/AndroidRuntime(7709): at dalvik.system.NativeStart.main(Native Method)
05-04 17:53:15.820: E/AndroidRuntime(7709): Caused by: java.lang.NullPointerException
05-04 17:53:15.820: E/AndroidRuntime(7709): at com.example.registerscreen.FriendListActivity.onCreate(FriendListActivity.java:68)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
05-04 17:53:15.820: E/AndroidRuntime(7709): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
I am able to get my phone contact on list view with name.On right side of list view I have added a button like invite button.Now I want when I click on this button then this button disappear and the check box is appeared with tick mark.
I tried many things but I am unable to do this.
public class FriendListActivity extends Activity {
SimpleCursorAdapter adapter;
ListView lvContacts;
Button b1;
CheckBox chk;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_friend_listview);
lvContacts = (ListView) findViewById(R.id.lv_friend_list);
ContentResolver cr = getContentResolver();
// Read Contacts
Cursor c = cr.query(ContactsContract.Contacts.CONTENT_URI,
new String[] { ContactsContract.Contacts._ID,ContactsContract.Contacts.DISPLAY_NAME }, null, null,
null);
// Attached with cursor with Adapter
adapter = new SimpleCursorAdapter(this, R.layout.activity_phonecontact,
c, new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { R.id.tv_name });
lvContacts.setAdapter(adapter);
b1 = (Button)findViewById(R.id.btn_invite);
chk = (CheckBox)findViewById(R.id.chk_frnd);
b1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
b1.setVisibility(View.GONE);
chk.setVisibility(View.VISIBLE);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img_frnd_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/include1"
android:background="@null"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:contentDescription="@string/imageView_contact_image"
android:src="@drawable/contactimage" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/include1"
android:layout_toRightOf="@+id/img_frnd_list"
android:paddingLeft="10dp"
android:paddingTop="35dp"
android:textSize="@dimen/contact_text_size"
android:text="@string/Contact_Name" />
<Button
android:text="Play"
android:id="@+id/btn_invite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingTop="80dp"
android:visibility="visible"
android:layout_below="@+id/include1"
android:paddingRight="10dp" >
</Button>
<CheckBox
android:id="@+id/chk_frnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_alignParentRight="true"
android:paddingTop="80dp"
android:layout_below="@+id/include1"
android:paddingRight="10dp" />
</RelativeLayout>