Android 转到Editfriends活动时应用程序崩溃

Android 转到Editfriends活动时应用程序崩溃,android,Android,以下是编辑朋友活动 package com.josephvarkey996gmail.test1; import android.app.ListActivity; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import andro

以下是编辑朋友活动

    package com.josephvarkey996gmail.test1;

import android.app.ListActivity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.ArrayAdapter;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseUser;

import java.util.List;


public class Editfriends extends ListActivity {
public  static final String Tag=Editfriends.class.getSimpleName();
    protected List<ParseUser> mUser;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        setContentView(R.layout.activity_editfriends);
    }

    @Override
    protected void onResume() {
        super.onResume();
        setProgressBarIndeterminateVisibility(true);
        ParseQuery<ParseUser> query= ParseUser.getQuery();
        query.orderByAscending(ParseConstants.key_Username);
        query.setLimit(1000);
        query.findInBackground(new FindCallback<ParseUser>() {
            @Override
            public void done(List<ParseUser> users, ParseException e) {
                setProgressBarIndeterminateVisibility(true);
                if (e== null){
                      mUser=users;
                    String[] username = new String[mUser.size()];
                    int i=0;
                    for(ParseUser user:mUser){
                        username[i]=user.getUsername();
                        i++;
                    }
                   ArrayAdapter<String> adapter = new ArrayAdapter<>(Editfriends.this,android.R.layout.simple_list_item_checked,username);
                    setListAdapter(adapter);
                }
                else
                {
                    Log.e(Tag,e.getMessage());
                    AlertDialog.Builder builder=new AlertDialog.Builder(Editfriends.this);
                    builder.setMessage(e.getMessage()).setTitle(R.string.error_title).setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();
                    dialog.show();
                }
            }
        });

    }

    @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_editfriends, 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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.josephvarkey996gmail.test1.Editfriends">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
07-21 19:42:05.397    9188-9188/com.josephvarkey996gmail.test1 E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.josephvarkey996gmail.test1, PID: 9188
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.josephvarkey996gmail.test1/com.josephvarkey996gmail.test1.Editfriends}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
     Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
            at android.app.ListActivity.onContentChanged(ListActivity.java:243)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:382)
            at android.app.Activity.setContentView(Activity.java:2145)
            at com.josephvarkey996gmail.test1.Editfriends.onCreate(Editfriends.java:27)
            at android.app.Activity.performCreate(Activity.java:5990)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

您的主要活动类正在扩展
列表活动
。这意味着您的xml文件需要一个
列表视图

尝试向XML中添加类似的内容:

<ListView android:id="@android:id/list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"/>

有关更多信息,请访问

如文件所述:

ListActivity有一个默认布局,由位于屏幕中心的单个全屏列表组成。但是,如果需要,可以通过在onCreate()中使用setContentView()设置自己的视图布局来自定义屏幕布局。为此,您自己的视图必须包含id为“@android:id/list”的ListView对象


您的activityy扩展了
列表activity
。因此,正如崩溃日志所说:

您的内容必须具有id属性为“android.R.id.list”的ListView

这意味着在xml文件中应该有一个
ListView
,其属性为
android:id:“android.R.id.list


这是因为
ListActivity
希望在is内容视图中找到
ListView

您使用的是
ListActivity
,这与正常的
活动有点不同

如果不执行任何操作,则ListActivity中只有一个视图,即
ListView

如果您调用
setContentView()
来提供您自己的布局(也许您希望显示的不仅仅是
ListView
),那么您的布局必须包含
ListView
,并且
ListView
必须具有
@android:id/list
的id

由于您提供的自定义版面由一个
RelativeLayout
和一个
TextView
组成,因此您的版面不符合此要求。因为这里似乎只有占位符内容,所以我将删除布局并删除对
setContentView()
的调用

您在logcat中发布的例外情况提到:

您的内容必须具有id属性为“android.R.id.list”的ListView


你看过错误信息了吗?我认为“你的内容必须有一个id属性为‘android.R.id.list’的ListView”是非常清楚的。你到底不明白什么?如果答案有效,你为什么不接受it@JosephVarkey-很高兴听到。既然我的回答行得通,你介意接受吗?谢谢