Created
August 1, 2011 20:04
-
-
Save zrsmith92/1118871 to your computer and use it in GitHub Desktop.
ListActivity subclass with requestWindowFeature()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): FATAL EXCEPTION: main | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.northwestern.NUShuttle/edu.northwestern.NUShuttle.Locations}: java.lang.NullPointerException | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.ActivityThread.access$2300(ActivityThread.java:125) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.os.Handler.dispatchMessage(Handler.java:99) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.os.Looper.loop(Looper.java:123) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.ActivityThread.main(ActivityThread.java:4627) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at java.lang.reflect.Method.invokeNative(Native Method) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at java.lang.reflect.Method.invoke(Method.java:521) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at dalvik.system.NativeStart.main(Native Method) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): Caused by: java.lang.NullPointerException | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at edu.northwestern.NUShuttle.Locations.onCreate(Locations.java:42) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) | |
08-01 14:37:49.394: ERROR/AndroidRuntime(1331): ... 11 more | |
08-01 14:37:49.404: WARN/ActivityManager(58): Force finishing activity edu.northwestern.NUShuttle/.Locations | |
08-01 14:37:49.414: WARN/ActivityManager(58): Force finishing activity edu.northwestern.NUShuttle/.NUShuttle | |
08-01 14:37:49.914: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{45022518 edu.northwestern.NUShuttle/.Locations} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.northwestern.NUShuttle; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.json.JSONArray; | |
import org.json.JSONException; | |
import android.app.ListActivity; | |
import android.app.ProgressDialog; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.AsyncTask; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuInflater; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.Window; | |
import android.widget.ListView; | |
import android.widget.SimpleAdapter; | |
import android.widget.TextView; | |
import edu.northwestern.NUShuttle.models.Location; | |
public class Locations extends ListActivity { | |
protected String title = "Select a Stop"; | |
@SuppressWarnings("unused") | |
private static final String TAG = "Locations Activity"; | |
//private JSONArray locations; | |
private ArrayList<Location> locations = new ArrayList<Location>(); | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); | |
super.onCreate(savedInstanceState); | |
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); | |
((TextView)findViewById(R.id.title)).setText(title); | |
((TextView)findViewById(R.id.virtual_time)).setText(Utilities.getVirtualDateDescription()); | |
new ListTask(this).execute(); | |
} | |
class ListTask extends AsyncTask<Void,Void,Void> { | |
protected ArrayList<Map<String,String>> listItems = new ArrayList<Map<String,String>>(); | |
protected Context mContext; | |
protected ProgressDialog pd; | |
public ListTask(Context context) { | |
mContext = context; | |
} | |
public void onPreExecute() { | |
pd = ProgressDialog.show(mContext, "", "Loading...", true); | |
} | |
protected Void doInBackground(Void... unused) { | |
Map<String, String>item; | |
try { | |
JSONArray data = Utilities.makeRequest("locations").getJSONArray("data"); | |
for ( int i = 0; i < data.length(); i++ ) { | |
item = new HashMap<String, String>(); | |
Location location = new Location(data.getJSONObject(i)); | |
item.put("name", location.getName()); | |
item.put("time", ""); | |
listItems.add(item); | |
locations.add(location); | |
} | |
} catch (JSONException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
public void onPostExecute(Void unused) { | |
if ( listItems == null || listItems.size() == 0 ) { | |
Utilities.showAlert(mContext, "Could not load stop data."); | |
} | |
setListAdapter(new SimpleAdapter( | |
mContext, | |
listItems, | |
R.layout.list_item, | |
new String[] {"name", "time"}, | |
new int[] {R.id.title, R.id.next_time} | |
)); | |
pd.hide(); | |
} | |
}; | |
public boolean onCreateOptionsMenu(Menu menu) { | |
MenuInflater i = getMenuInflater(); | |
i.inflate(R.menu.menu, menu); | |
return true; | |
} | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch(item.getItemId()) { | |
case R.id.settings: { | |
Intent settingsIntent = new Intent(getApplicationContext(), Settings.class); | |
startActivity(settingsIntent); | |
break; | |
} | |
case R.id.view_map: { | |
Intent mapIntent = new Intent(getApplicationContext(), ShowMap.class); | |
startActivity(mapIntent); | |
break; | |
} | |
} | |
return true; | |
} | |
@Override | |
protected void onListItemClick(ListView l, View v, int position, long id) { | |
Location location = locations.get(position); | |
((MyApplication) getApplicationContext()).setLocation(location); | |
Intent stopsIntent = new Intent(getApplicationContext(), StopsForLocation.class); | |
startActivity(stopsIntent); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment