Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get ListView data from one activity to another using setOnClickListener
    primarykey
    data
    text
    <p>In my listview there are to feilds,ward number and the date.i want to get these data to new activity when i'am clicking a listview.but in this there is a runtime error and i have no idea to how to fix it.</p> <p>this is my dashboardActivity.java file,</p> <pre><code>public class DashboardActivity extends ListActivity implements FetchDataListener{ UserFunctions userFunctions; Button btnLogout; TextView resultView; private ProgressDialog dialog; //private String email; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** * Dashboard Screen for the application * */ // Check login status in database userFunctions = new UserFunctions(); if(userFunctions.isUserLoggedIn(getApplicationContext())){ setContentView(R.layout.dashboard); initView(); ListView lv = getListView(); // listening to single list item on click lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // selected item TextView txtviewWard= (TextView) view.findViewById(R.id.ward_number); String ward = txtviewWard.getText().toString(); TextView txtviewDate= (TextView) view.findViewById(R.id.date_time); String dateTime = txtviewDate.getText().toString(); // Launching new Activity on selecting single List Item Intent i = new Intent(getApplicationContext(), SingleListItem.class); // sending data to new activity i.putExtra("ward", ward); i.putExtra("dateTime", dateTime); startActivity(i); } }); btnLogout = (Button) findViewById(R.id.btnLogout); btnLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub userFunctions.logoutUser(getApplicationContext()); Intent login = new Intent(getApplicationContext(), LoginActivity.class); login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(login); // Closing dashboard screen finish(); } }); }else{ // user is not logged in show login screen Intent login = new Intent(getApplicationContext(), LoginActivity.class); login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(login); // Closing dashboard screen finish(); } } private void initView() { // show progress dialog dialog = ProgressDialog.show(this, "", "Loading..."); Intent intent = getIntent(); String email = intent.getStringExtra(LoginActivity.EMAIL); String url = "http://pubbapp.comze.com/pubapp1.php?email=" + email; FetchDataTask task = new FetchDataTask(this); task.execute(url); } public void onFetchComplete(List&lt;Application&gt; data) { // dismiss the progress dialog if(dialog != null) dialog.dismiss(); // create new adapter ApplicationAdapter adapter = new ApplicationAdapter(this, data); // set the adapter to list setListAdapter(adapter); } public void onFetchFailure(String msg) { // dismiss the progress dialog if(dialog != null) dialog.dismiss(); // show failure message Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); } } </code></pre> <p>this is my SingleListItem.java file,</p> <pre><code>public class SingleListItem extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.single_list_item_view); TextView txtWard = (TextView) findViewById(R.id.ward_number); TextView txtDate = (TextView) findViewById(R.id.date_time); Intent i = getIntent(); // getting attached intent data String wardNumber = i.getStringExtra("ward"); String dateTime = i.getStringExtra("dateTime"); // displaying selected product name txtWard.setText(wardNumber); txtDate.setText(dateTime); } </code></pre> <p>this is my xml file,</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/ward_number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dip" android:text="wardNumber" android:textColor="#ffffff" android:textSize="25dip" android:textStyle="bold" /&gt; &lt;TextView android:id="@+id/date_time" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Date" android:padding="10dip" android:textColor="#ffffff" android:textSize="20dip" android:textStyle="bold" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>and this is the error in the LogCat,</p> <pre><code>12-02 19:10:01.100: E/AndroidRuntime(22705): FATAL EXCEPTION: main 12-02 19:10:01.100: E/AndroidRuntime(22705): java.lang.NullPointerException 12-02 19:10:01.100: E/AndroidRuntime(22705): at com.example.androidhive.DashboardActivity$1.onItemClick(DashboardActivity.java:59) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.widget.ListView.performItemClick(ListView.java:3745) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1980) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.os.Handler.handleCallback(Handler.java:587) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.os.Handler.dispatchMessage(Handler.java:92) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.os.Looper.loop(Looper.java:130) 12-02 19:10:01.100: E/AndroidRuntime(22705): at android.app.ActivityThread.main(ActivityThread.java:3691) 12-02 19:10:01.100: E/AndroidRuntime(22705): at java.lang.reflect.Method.invokeNative(Native Method) 12-02 19:10:01.100: E/AndroidRuntime(22705): at java.lang.reflect.Method.invoke(Method.java:507) 12-02 19:10:01.100: E/AndroidRuntime(22705): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847) 12-02 19:10:01.100: E/AndroidRuntime(22705): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 12-02 19:10:01.100: E/AndroidRuntime(22705): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>please help me to fix this error. thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload