This question has already been answered:

From the adapter, data is inserted into the textView in the Item, when trying to output the data in a toast in this way Toast.makeText(CardActivity.this, tvInviz.getText().toString(),Toast.LENGTH_LONG).show(); I get the error android.widget.TextView.getText()' on a null object reference' use https://github.com/Diolor/Swipecards

Item

 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center" android:layout_width="300dp" android:layout_height="250dp"> <TextView android:id="@+id/helloText" android:textSize="40sp" android:textColor="@android:color/white" android:background="#E339" android:gravity="center" android:layout_width="match_parent" android:layout_height="match_parent" /> <View android:id="@+id/item_swipe_left_indicator" android:alpha="0" android:layout_width="20dp" android:layout_height="20dp" android:layout_margin="10dp" android:background="#A5F" /> <View android:id="@+id/item_swipe_right_indicator" android:alpha="0" android:layout_width="20dp" android:layout_height="20dp" android:layout_margin="10dp" android:layout_gravity="right" android:background="#5AF" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="Medium Text" android:id="@+id/textView3" /> 

Activity

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="com.example.vadik.alfatest.CardActivity"> <com.lorentzos.flingswipe.SwipeFlingAdapterView android:id="@+id/frame" android:background="#ffeee9e2" android:layout_width="match_parent" android:layout_height="match_parent" app:rotation_degrees="15.5" tools:context=".CardActivity" /> </RelativeLayout> 

Full code

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card); tvInviz = (TextView)findViewById(R.id.textView3); SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame); dbHelper = new DBHelper(this); db = dbHelper.getReadableDatabase(); Intent intent1 = getIntent(); selectionArgs = intent1.getStringArrayExtra("selection_args"); String [] forQuery = new String[] {"_id","col_rus","col_eng"}; cursor = db.query("my_table",forQuery,"col_category =?",selectionArgs,null,null,null); final ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); cursor.moveToFirst(); while(!cursor.isAfterLast()) { m = new HashMap<String, Object>(); m.put(ATTRIBUTE_RUS_TRANSLATE,cursor.getString(cursor.getColumnIndex(DBHelper.COL_RUS))); m.put(ATTRIBUTE_ENG_TRANSLATE,cursor.getString(cursor.getColumnIndex(DBHelper.COL_ENG))); data.add(m); cursor.moveToNext(); } String[] from = new String[]{ATTRIBUTE_RUS_TRANSLATE,ATTRIBUTE_ENG_TRANSLATE} ; int[] to = new int[]{R.id.helloText,R.id.textView3}; final SimpleAdapter simpleAdapter = new SimpleAdapter(this,data,R.layout.item,from,to); flingContainer.setAdapter(simpleAdapter); flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() { @Override public void removeFirstObjectInAdapter() { data.remove(0); simpleAdapter.notifyDataSetChanged(); } @Override public void onLeftCardExit(Object dataObject) { Toast.makeText(CardActivity.this, "Left!", Toast.LENGTH_SHORT).show(); } @Override public void onRightCardExit(Object dataObject) { Toast.makeText(CardActivity.this, "Right!", Toast.LENGTH_SHORT).show(); } @Override public void onAdapterAboutToEmpty(int itemsInAdapter) { simpleAdapter.notifyDataSetChanged(); Log.d("LIST", "notified"); } @Override public void onScroll(float v) { } }); flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() { @Override public void onItemClicked(int itemPosition, Object dataObject) { Toast.makeText(CardActivity.this, tvInviz.getText().toString(),Toast.LENGTH_LONG).show(); } }); } 

}

Reported as a duplicate by YurySPb. android Jul 30 '16 at 7:39 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    That's right, because you don't have an Activity textView .

    You should get the tex either by itemPosition from data , or directly from dataObject