我是android新手。我正在构建一个事件应用程序,每次按下即将发生的事件按钮,应用程序崩溃并给出“不幸****已停止”消息。
logcat说它是运行时异常。
请帮帮我。谢谢。
这是我的活动代码;
package com.example.mrspegasus.eventsapp;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.List;
public class EventsUpComing extends ListActivity
{
protected List<ParseObject> mEvents;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_events_up_coming);
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("EVENTS");
query.findInBackground(new FindCallback<ParseObject>()
{
@Override
public void done(List<ParseObject> event, ParseException e)
{
if(e == null)
{
mEvents = event;
EventAdapter adapter = new EventAdapter(getListView().getContext(),mEvents);
setListAdapter(adapter);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_events_up_coming, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
这是布局;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mrspegasus.eventsapp.EventsUpComing"
android:background="@drawable/img4">
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Choose A Date"
android:id="@+id/btdate"
android:layout_below="@+id/Titlebar"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textStyle="bold" />
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listViewUpcomingEvents"
android:layout_below="@+id/btdate"
android:layout_alignLeft="@+id/Logo"
android:layout_alignStart="@+id/Logo"
android:layout_marginTop="52dp" />
在logcat中它说;
09-19 12:26:43.641 20313-20313/com.example.mrspegasus.eventsapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.mrspegasus.eventsapp, PID: 20313
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mrspegasus.eventsapp/com.example.mrspegasus.eventsapp.EventsUpComing}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
at android.app.