简体   繁体   中英

Android application can't run on Galaxy S4 but can run at Galaxy Ace 2

The android application that I develop doesn't work on galaxy s4 . Everything is pretty normal when I run it. The MainActivity (First Page) is fine and working However when I press the button, which will switch to the activity that will retrieve data from web service and publish it on the phone, the application force closes! I tried the same application at my galaxy ace 2 and everything is fine, after the button is pressed - it works normally and gives me the correct output. Any ideas what is wrong with my android application?

Here is the code for my MainActivity(First page) button :

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

And here is the AndroidXMLParsingActivity class that will retrieve data from the web service:

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

}
});
}
}

If AndroidXMLParsingActivity is the activity to be opened after the MainActivity , why don't you use this code to open the activity.

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

in place of your code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM