-1

here is the EditFriends activity..........................................

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

here is the xml of Editfriends ............................................

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

im learning ,so cant understand the eror. here is the logcat..............................

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)
Joseph Varkey
  • 41
  • 1
  • 3
  • Did you even read the error message? I think *"Your content must have a ListView whose id attribute is 'android.R.id.list'"* is pretty clear. What exactly you didn't understand? – m0skit0 Jul 21 '15 at 15:03
  • If the answer works why didn't you accept it – Soham Jul 21 '15 at 15:25

3 Answers3

0

Your main activity class is extending a ListActivity. This means that your xml file needs a ListView.

Try adding something like this to your XML:

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

More information can be found at http://developer.android.com/reference/android/app/ListActivity.html.

As the documentation states:

ListActivity has a default layout that consists of a single, full-screen list in the center of the screen. However, if you desire, you can customize the screen layout by setting your own view layout with setContentView() in onCreate(). To do this, your own view MUST contain a ListView object with the id "@android:id/list

mattfred
  • 2,689
  • 1
  • 22
  • 38
0

Your activtiy extends ListActivity. So as the crash logs say :

Your content must have a ListView whose id attribute is 'android.R.id.list'

This mean that in your xml file you should have a ListView with the attribute android:id:"android.R.id.list.

This is because ListActivity expect to find a ListView in is content view.

sonic
  • 1,894
  • 1
  • 18
  • 22
0

You are using a ListActivity, which is a bit different than a normal Activity.

If you do nothing, then your ListActivity will have a single View in it, which is a ListView.

If you call setContentView() to supply your own layout (perhaps you want to display more than just a ListView), then your layout must contain a ListView and that ListView must have an id of @android:id/list.

Since you are providing a custom layout that consists of a RelativeLayout with a single TextView, your layout does not pass this requirement. Since it looks like you just have placeholder content there, I would remove the layout and remove the call to setContentView().

The exception you posted from your logcat mentions this:

Your content must have a ListView whose id attribute is 'android.R.id.list'

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120