Я разрабатываю приложение для чата для Android.
Я застрял, показывая контакты во всплывающем окне. Я притворяюсь, что показываю их в правой части экрана, как Google+ показывает меню. Проблема в том, что я искал много структур, чтобы показать их, и, наконец, тот, который я видел, который не устарел, - это popupWindow. Пожалуйста, если это неправильно, я буду признателен за вашу помощь.
Когда я пытаюсь выполнить код, я получаю эту ошибку (я пробовал много вещей, и на самом деле это то, что у меня есть): java.lang.NullPointerException: попытка вызвать виртуальный метод 'void android.widget.TextView.setText (java .lang.CharSequence)» для ссылки на нулевой объект в osmuogar.letter.interfaz.conversacion.Sala.showContacts(Sala.java:100)
Код Java---
public void showContacts(MenuItem item){
LayoutInflater layoutInflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final ViewGroup popupView = (ViewGroup)layoutInflater.inflate(R.layout.lista_amigos, null);
PopupWindow popupWindow = new PopupWindow(popupView, RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
final LinearLayout layout = (LinearLayout) popupView.findViewById(R.id.linearLayoutAmigos);
layout.inflate(popupView.getContext(),R.layout.contact,null);
TextView contactName = (TextView) layout.findViewById(R.id.contactname);
contactName.setText("contacto1");
popupView.addView(layout);
popupWindow.setFocusable(true);
popupWindow.update();
popupWindow.showAtLocation(findViewById(R.id.mainLayout), Gravity.RIGHT,0,0);
Мои макеты --- --lista_amigos
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollViewAmigos">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayoutAmigos">
</LinearLayout>
</ScrollView>
</LinearLayout>
--контакт
<?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="wrap_content"
android:layout_gravity="left"
android:background="#ffffff">
<TextView
android:id="@+id/contactname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView"
android:text="contact"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textSize="24sp" />
</RelativeLayout>
Спасибо за помощь.