Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Intent with actions
    primarykey
    data
    text
    <p>Right. I have an action that needs to call another activity. As I understand this, I need to use Intents to do so if I want to parse values to this activity.</p> <p>However, my code fails and im a little lost as to why.</p> <p>My main activity:</p> <pre><code>/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); final ArrayList&lt;menuItem&gt; AMI = new ArrayList&lt;menuItem&gt;(); /*Menu item: String name, String menu ID*/ /*ToDo: Logic to fecth new menu structure from server*/ menuItem MI1 = new menuItem("menu item 1","1"); menuItem MI2 = new menuItem("menu item 2","2"); AMI.add(MI1); AMI.add(MI2); GridView gridview = (GridView) findViewById(R.id.GridView01); gridview.setAdapter(new menuAdapter(this, AMI)); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { //Toast.makeText(Runner.this, AMI.get(position).getMenuID(), Toast.LENGTH_SHORT).show(); Intent myIntent = new Intent(v.getContext(), showMenu.class); myIntent.putExtra("parentID", AMI.get(position).getMenuID()); startActivityForResult(myIntent, 0); } }); </code></pre> <p>The "Toast" works just fine, however when I call the showMenu class it crashes. The showMenu class looks as follows:</p> <pre><code>public class showMenu extends Activity{ public String menuParent = ""; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.submenu); Bundle extras = getIntent().getExtras(); if(extras !=null) { menuParent = extras.getString("parentID"); } /*ToDo: Logic to fecth new menu structure from server*/ final ArrayList&lt;menuItem&gt; AMI = new ArrayList&lt;menuItem&gt;(); menuItem MI1 = new menuItem("submenu 1","1"); menuItem MI2 = new menuItem("submenu 2","2"); AMI.add(MI1); AMI.add(MI2); GridView gridview = (GridView) findViewById(R.id.GridView01); gridview.setAdapter(new subMenuAdapter(this, AMI)); } public class subMenuAdapter extends BaseAdapter { private ArrayList&lt;menuItem&gt; MIL = new ArrayList&lt;menuItem&gt;(); public static final int ACTIVITY_CREATE = 10; public subMenuAdapter(Context c, ArrayList&lt;menuItem&gt; AMI) { MIL = AMI; } public int getCount() { return MIL.size(); } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } public View getView(int position, View convertView, ViewGroup parent) { View v; if (convertView == null) { LayoutInflater li = getLayoutInflater(); v = (LinearLayout) li.inflate(R.layout.grid_item, null); TextView tv = (TextView)v.findViewById(R.id.grid_text); tv.setText(MIL.get(position).getMenuname()); } else { v = convertView; } return v; } } </code></pre> <p>}</p> <p>Any idea why it crashes?</p>
    singulars
    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