Note that there are some explanatory texts on larger screens.

plurals
  1. POMenu Handler for the activities
    primarykey
    data
    text
    <p>Please help me out regarding the menu handler . I want to make menu handler which i can call in different activities . All things are working fine . list is fetching from the server and menu are also appearing but when i click on the any menu button "Force to close" Pops up . </p> <p>Here is the meun handler class </p> <pre><code>package com.droidnova.android.howto.optionmenu; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.content.Intent; public class MenuHandler extends Activity{ private Activity activity; public MenuHandler(Activity activity) { this.activity = activity; } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = activity.getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings: Intent intent = new Intent(this, ShowSettings.class); startActivity(intent); break; case R.id.services: Intent intent2 = new Intent(this, Test.class); startActivity(intent2); break; case R.id.Quit: finish(); break; default: break; } return true; } } </code></pre> <p>over here i want the same menu to work . </p> <p>package com.droidnova.android.howto.optionmenu;</p> <pre><code>import java.util.ArrayList; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; public class Test extends ListActivity { private MenuHandler menuHandler; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listplaceholder); menuHandler = new MenuHandler(this); ArrayList&lt;HashMap&lt;String, String&gt;&gt; mylist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); JSONObject json = JSONfunctions.getJSONfromURL("http://midsweden.gofreeserve.com/fetch.php"); try{ JSONArray earthquakes = json.getJSONArray("earthquakes"); for(int i=0;i&lt;earthquakes.length();i++){ HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); JSONObject e = earthquakes.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("name", "Earthquake name:" + e.getString("name")); map.put("password", "Magnitude: " + e.getString("password")); mylist.add(map); } }catch(JSONException e) { Log.e("log_tag", "Error parsing data "+e.toString()); } ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.test, new String[] { "name", "magnitude" }, new int[] { R.id.item_title, R.id.item_subtitle }); setListAdapter(adapter); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { @SuppressWarnings("unchecked") HashMap&lt;String, String&gt; o = (HashMap&lt;String, String&gt;) lv.getItemAtPosition(position); Toast.makeText(Test.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { return menuHandler.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { return menuHandler.onOptionsItemSelected(item); } } </code></pre> <p>Here is what i am getting in the logcat <img src="https://i.stack.imgur.com/OonEn.png" alt="enter image description here"></p>
    singulars
    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.
 

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