Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:39:03+00:00 2026-06-16T13:39:03+00:00

I’m trying to send some data from my ListView to another activity through a

  • 0

I’m trying to send some data from my ListView to another activity through a single option list view fragment.
Here is how flow of data is supposed to be:

ListView (upon choosing an option) -> Single option list view fragment (again, upon choosing an option) -> AnotherActivity.

Code which sends the data from ListView to Fragment:

Bundle b = new Bundle();
b.putString("id", str_projectid);
Projectviewoptions pv = new Projectviewoptions();
pv.setArguments(b);

Projectviewoptions newFragment = new Projectviewoptions();
newFragment.show(getFragmentManager(), "projectoptions");

Code fragment class which receives the data and then sends it to the other activity:

public class Projectviewoptions extends DialogFragment {

String[] option_array = new String[] {"Project details","Edit","Delete","Mark Done"};
Bundle idbundle = getArguments(); 
String myid= idbundle.getString("id"); 

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Options")
           .setItems(option_array, new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {

                switch(which) {

                case 0: Intent intent = new Intent(getActivity(),ViewProjectDetails.class);
                        intent.putExtra("id", myid);
                        startActivity(intent);
                        break;




                }

           }
    });
    return builder.create();
}
}

Code in the OtherActivity which receives the data passed by the fragment:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_project_details);

    String id = getIntent().getExtras().getString("id");
    Toast.makeText(this, id, Toast.LENGTH_LONG).show();
}

The problem:
When I select an option from the ListView, the app crashes. If I remove the code which deals with passing of the data, the app works fine.
That is, if you remove the following code in the ListView:

/*Bundle b = new Bundle();
      b.putString("id", str_projectid);
      Projectviewoptions pv = new Projectviewoptions();
      pv.setArguments(b);*/

and the following, in fragment class:

//Bundle idbundle = getArguments(); 
//String myid= idbundle.getString("id"); 

Here is the LogCat:

12-30 23:21:09.620: W/dalvikvm(7406): threadid=1: thread exiting with uncaught
exception (group=0x409c01f8)
12-30 23:21:09.653: E/AndroidRuntime(7406): FATAL EXCEPTION: main
12-30 23:21:09.653: E/AndroidRuntime(7406): java.lang.NullPointerException
12-30 23:21:09.653: E/AndroidRuntime(7406):     at     
com.kk.project.Projectviewoptions.<init>(Projectviewoptions.java:14)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at 
com.kk.project.ProjectExplorer.onListItemClick(ProjectExplorer.java:53)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at 
android.app.ListActivity$2.onItemClick(ListActivity.java:319)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at 
android.widget.AdapterView.performItemClick(AdapterView.java:292)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at    
android.widget.AbsListView.performItemClick(AbsListView.java:1058)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at  
android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at   
android.widget.AbsListView$1.run(AbsListView.java:3168)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at 
android.os.Handler.handleCallback(Handler.java:605)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at   
android.os.Handler.dispatchMessage(Handler.java:92)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at     
android.os.Looper.loop(Looper.java:137)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at  
android.app.ActivityThread.main(ActivityThread.java:4424)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at   
java.lang.reflect.Method.invokeNative(Native Method)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at 
java.lang.reflect.Method.invoke(Method.java:511)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at  
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at  
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-30 23:21:09.653: E/AndroidRuntime(7406):     at    
dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:39:04+00:00Added an answer on June 16, 2026 at 1:39 pm

    You cannot access the Fragment’s arguments outside of any method, simply move this code into onCreateDialog():

    Bundle idbundle; 
    String myid; 
    
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        idbundle = getArguments();
        myid = idbundle.getString("id");
        ...
    

    The problem is that getArguments(); returns null when you try to access it before the Fragment’s lifecycle begins, so idbundle.getString() is an NPE.


    Addition
    You are creating two different copies of the same fragment named pv and newFragment, you should show pv and remove newFragment entirely:

    Bundle b = new Bundle();
    b.putString("id", str_projectid);
    Projectviewoptions pv = new Projectviewoptions();
    pv.setArguments(b);
    pv.show(getFragmentManager(), "projectoptions");
    

    Projectviewoptions newFragment = new Projectviewoptions();
    newFragment.show(getFragmentManager(), "projectoptions");
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I am using jsonparser to parse data and images obtained from json response. When
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.