1

I have a listview that receives user input from edit text in a different activity via key "hubahuba". When I click on the tap that contains this .class I receive the NullPointerException Error based on the logcat I know it has to do with my "String trackinput" Line PLEASE any help guys???

 public static ArrayList<String> list = new ArrayList<String>();
 public static ArrayAdapter<String> adapter;

LisstView lv;
String trackinput;

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

           //listViewCode

    ListView lv = (ListView)findViewById(android.R.id.list);

            //Intent to receive from other activity

    Intent i = getIntent();

    String trackinput = i.getExtras().getString("hubahuba");

            //basic adapter

    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
    lv.setAdapter(adapter);
    list.add(0, trackinput);
    adapter.notifyDataSetChanged();
    setListAdapter(adapter);

}

This is from activity 1 going to the listView in Activity 2:

public void onClick(View v) { 
 Intent i = new Intent(this, ArgueListActivity.class); 
 i.putExtra("hubahuba",whatedit.getText().toString()); 
 whatedit.setText("");
}
LimpLimp
  • 37
  • 2
  • 11
  • In `onCreate()` here, you're declaring a local variable called `lv` that hides what I assume is the member variable. Are you initializing the member `lv` at some point? – Collin Oct 29 '13 at 19:05
  • @Collin Can you provide an example how initializing the member lv. – LimpLimp Oct 29 '13 at 19:45

1 Answers1

0

You don't have to create a new instance of Intent

You can just do it like this:

String trackinput = getIntent().getStringExtra("hubahuba");

Also as Collin pointed out

LisstView lv;

and

ListView lv = (ListView)findViewById(android.R.id.list);

are ambiguous


After you put data into the intent you have to start the activity, and pass it the intent to it.
public void onClick(View v) { 
 Intent i = new Intent(this, ArgueListActivity.class); 
 i.putExtra("hubahuba",whatedit.getText().toString()); 
 whatedit.setText("");
 startActivity(i)
}
meda
  • 45,103
  • 14
  • 92
  • 122
  • @LimpLimp please show the code that puts the string in the intent – meda Oct 29 '13 at 20:19
  • When I add this method I no longer get the NullPointer but it does not receive the bundle any ideas on how to implement both ( Bundle and String trackinput = getIntent().getStringExtra("hubahuba"); ) – LimpLimp Nov 20 '13 at 02:15