我开发的 android 应用程序不适用于Galaxy s4。当我运行它时,一切都很正常。MainActivity (第一页)很好并且工作但是当我按下按钮时,它将切换到将从 Web 服务检索数据并将其发布到手机上的活动,应用程序强制关闭!我在我的Galaxy ace 2上尝试了相同的应用程序,一切都很好,按下按钮后 - 它正常工作并给我正确的输出。任何想法我的android应用程序有什么问题?
这是我的MainActivity(First page) 按钮的代码:
Button recommendButton = (Button) findViewById(R.id.button1);
Button dateBtn = (Button) findViewById(R.id.button2);
recommendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String packageName = AndroidXMLParsingActivity.class
.getPackage().getName();
String packageAndClassName = AndroidXMLParsingActivity.class
.getName();
Intent intent = new Intent().setClassName(packageName,
packageAndClassName);
startActivity(intent);
}
});
这是将从 Web 服务检索数据的AndroidXMLParsingActivity类:
public class AndroidXMLParsingActivity extends ListActivity {
// All static variables
static final String URL = "http://api.eventful.com/rest/events/search?app_key=42t54cX7RbrDFczc&location=singapore";
// XML node keys
static final String KEY_EVENT = "event"; // parent node
static final String KEY_TITLE = "title";
static final String KEY_DESC = "description";
static final String KEY_URL = "url";
static final String KEY_START_TIME = "start_time";
static final String KEY_VENUE_NAME = "venue_name";
static final String KEY_COUNTRY_NAME = "country_name";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_EVENT);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
map.put(KEY_URL, parser.getValue(e, KEY_URL));
map.put(KEY_START_TIME, parser.getValue(e, KEY_START_TIME));
map.put(KEY_VENUE_NAME, parser.getValue(e, KEY_VENUE_NAME));
map.put(KEY_COUNTRY_NAME, parser.getValue(e, KEY_COUNTRY_NAME));
// adding HashList to ArrayList
menuItems.add(map);
}
// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.list_item, new String[] { KEY_TITLE, KEY_DESC, KEY_COUNTRY_NAME,
KEY_VENUE_NAME, KEY_START_TIME }, new int[] {
R.id.title,R.id.description, R.id.countryName, R.id.venueName,
R.id.startTime });
setListAdapter(adapter);
// selecting single ListView item
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String title = ((TextView) view.findViewById(R.id.title))
.getText().toString();
String description = ((TextView) view
.findViewById(R.id.description)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_DESC, description);
startActivity(in);
}
});
}
}