Android应用程序无法在Galaxy S4上运行,但可以在Galaxy Ace 2上运行

时间:2013-07-19 07:17:03

标签: java android galaxy

我开发的Android应用程序无法在 galaxy s4 上运行。 当我运行它时,一切都很正常。 MainActivity (第一页)很好并且正常工作但是当我按下按钮时,该按钮将切换到将从Web服务检索数据并将其发布到手机上的活动,应用程序将关闭! 我在 galaxy ace 2 上尝试了相同的应用程序,一切都很好,按下按钮后 - 它正常工作并给我正确的输出。任何想法我的Android应用程序有什么问题?

以下是 MainActivity(首页)按钮的代码

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);
}
});

以下是 AndroidXMLParsingActivity 类,它将从Web服务中检索数据:

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);

}
});
}
}

1 个答案:

答案 0 :(得分:0)

如果AndroidXMLParsingActivityMainActivity后要打开的活动,为什么不使用此代码打开活动。

startActivity(new Intent(this, AndroidXMLParsingActivity.class));

代替您的代码:

String packageName = AndroidXMLParsingActivity.class
.getPackage().getName();
String packageAndClassName = AndroidXMLParsingActivity.class
.getName();
Intent intent = new Intent().setClassName(packageName,
packageAndClassName);
startActivity(intent);