2015-07-21 66 views
-1

这里是EditFriends活动.................................... .......当编辑朋友活动时,应用程序崩溃

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

这里是Editfriends的xml .............................. ..............

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

即时学习,所以不能理解错误。这里是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) 
+0

你甚至阅读的错误信息?我认为*“你的内容必须有一个ListView,其id属性是'android.R.id.list'”*很清楚。你究竟是不明白的? – m0skit0

+0

如果答案有效,你为什么不接受它 – Soham

回答

0

您的主要活动类是扩展ListActivity。这意味着你的xml文件需要一个ListView

尝试增加这样的事情你的XML:

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

更多信息,http://developer.android.com/reference/android/app/ListActivity.html找到。

由于文档状态:

ListActivity拥有一个由在屏幕中心的单一,全屏幕列表的默认布局。但是,如果您愿意,可以通过在onCreate()中使用setContentView()设置您自己的视图布局来自定义屏幕布局。要做到这一点,你自己的观点必须包含id为“一个ListView对象@android:ID /列表

+1

它比thanx好! –

+0

@JosephVarkey - 很高兴听到。既然我的答案确实奏效,你会介意接受吗?谢谢 – mattfred

0

你activtiy延伸ListActivity因此,作为崩溃日志说:

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

这意味着,在您的XML文件,你应该与属性的ListViewandroid:id:"android.R.id.list

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

0

您正在使用的是ListActivity,与正常的Activity有点不同。

如果你什么都不做,那么你的ListActivity将有一个单一的视图,它是一个ListView

如果调用setContentView()提供自己的布局(也许你想显示更多的不仅仅是一个ListView),那么你的布局必须包含ListViewListView必须@android:id/list的ID。

由于您提供的自定义布局由RelativeLayout与单个TextView组成,因此您的布局未通过此要求。由于您看起来只有占位符内容,因此我会移除布局并删除对setContentView()的呼叫。

您从logcat中发布的例外提到了这一点:

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

相关问题