我在使用logcat时遇到以下问题-android.widget.ImageView无法转换为com.parse.ParseImageView

我本质上是试图在Parse上检索一个包含字符串,数字和文件(图像)的列表。 在执行过程中,我收到以下日志消息:

 08-23 11:42:32.291: E/AndroidRuntime(1283): FATAL EXCEPTION: main
    08-23 11:42:32.291: E/AndroidRuntime(1283): Process: com.dooba.beta, PID: 1283
    08-23 11:42:32.291: E/AndroidRuntime(1283): java.lang.ClassCastException: android.widget.ImageView cannot be cast to com.parse.ParseImageView
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.dooba.beta.Fragment1$1.done(Fragment1.java:174)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.parse.FindCallback.internalDone(FindCallback.java:45)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.parse.FindCallback.internalDone(FindCallback.java:1)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.parse.Parse$6$1.run(Parse.java:888)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.os.Handler.handleCallback(Handler.java:733)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.os.Handler.dispatchMessage(Handler.java:95)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.os.Looper.loop(Looper.java:136)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.app.ActivityThread.main(ActivityThread.java:5017)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at java.lang.reflect.Method.invoke(Method.java:515)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    08-23 11:42:32.291: E/AndroidRuntime(1283):     at dalvik.system.NativeStart.main(Native Method)

以下是活动代码

public class Fragment1 extends Fragment {

    public interface Constants {
        String LOG = "com.dooba.beta";
    }

    private String currentUserId;
    private ArrayAdapter<String> namesArrayAdapter;
    private ArrayList<String> names;
    private ArrayList<String> age;
    private ArrayList<String> headline;
    private ArrayList<String> activityname;

    private ArrayList<Images> alProfilePicture;
    private ListView usersListView;
    private Button logoutButton;
    String userGender = ParseUser.getCurrentUser().getString("Gender");
    String activityName = ParseUser.getCurrentUser().getString("ActivityName");
    Number maxDistance = ParseUser.getCurrentUser().getNumber(
            "Maximum_Distance");
    String userLookingGender = ParseUser.getCurrentUser().getString(
            "Looking_Gender");
    Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
    Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
    Number userage = ParseUser.getCurrentUser().getNumber("Age");

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setConversationsList();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1_layout, container,
                false);

        return view;
    }

    private void setConversationsList() {
        currentUserId = ParseUser.getCurrentUser().getObjectId();
        names = new ArrayList<String>();
        age = new ArrayList<String>();
        headline = new ArrayList<String>();
        activityname = new ArrayList<String>();

        alProfilePicture = new ArrayList<Images>();

        // String userActivitySelectionName = null;

        ParseQuery<ParseUser> query = ParseUser.getQuery();

        // query.whereEqualTo("ActivityName",userActivitySelectionName);

        query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                .getObjectId());
        // users with Gender = currentUser.Looking_Gender
        query.whereEqualTo("Gender", userLookingGender);
        // users with Looking_Gender = currentUser.Gender
        query.whereEqualTo("Looking_Gender", userGender);
        query.setLimit(1);
        query.whereEqualTo("ActivityName", activityName);
        // query.whereGreaterThanOrEqualTo("Age", minimumAge);
        // query.whereLessThanOrEqualTo("Age", maximumAge);
        query.orderByDescending("Name");


        ParseQuery<ParseUser> query1 = ParseUser.getQuery();

        // query.whereEqualTo("ActivityName",userActivitySelectionName);

        query1.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                .getObjectId());
        // users with Gender = currentUser.Looking_Gender
        query1.whereEqualTo("Gender", userLookingGender);
        // users with Looking_Gender = currentUser.Gender
        query1.whereEqualTo("Looking_Gender", userGender);
        query1.setLimit(1);
        query1.whereEqualTo("ActivityName", activityName);
        // query.whereGreaterThanOrEqualTo("Age", minimumAge);
        // query.whereLessThanOrEqualTo("Age", maximumAge);
        query1.orderByDescending("Name");

        ParseQuery<ParseUser> query11 = ParseUser.getQuery();

        // query.whereEqualTo("ActivityName",userActivitySelectionName);

        query11.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                .getObjectId());
        // users with Gender = currentUser.Looking_Gender
        query11.whereEqualTo("Gender", userLookingGender);
        // users with Looking_Gender = currentUser.Gender
        query11.whereEqualTo("Looking_Gender", userGender);
        query11.setLimit(1);
        query11.whereEqualTo("ActivityName", activityName);
        // query.whereGreaterThanOrEqualTo("Age", minimumAge);
        // query.whereLessThanOrEqualTo("Age", maximumAge);
        query11.orderByDescending("Name");

        Log.d(Constants.LOG, "");




        query.findInBackground(new FindCallback<ParseUser>() {

            @Override
            public void done(List<ParseUser> objects,ParseException e) {

                for(int i=0;i<objects.size();i++){
                    // Do whatever you need to extract object from "users"
                    ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
                    query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                            .getObjectId());
                    // users with Gender = currentUser.Looking_Gender
                    query.whereEqualTo("Gender", userLookingGender);
                    // users with Looking_Gender = currentUser.Gender
                    query.whereEqualTo("Looking_Gender", userGender);
                    query.setLimit(1);
                    query.whereEqualTo("ActivityName", activityName);
                    // query.whereGreaterThanOrEqualTo("Age", minimumAge);
                    // query.whereLessThanOrEqualTo("Age", maximumAge);
                    query.orderByDescending("Name");

                    ParseFile image = objects.get(i).getParseFile("ProfilePicture");


                    ParseImageView imageView = (ParseImageView) getView().findViewById(R.id.profilePictureresult);

                     // The placeholder will be used before and during the fetch, to be replaced by the fetched image
                     // data.
                     imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
                     imageView.setParseFile(image);
                     imageView.loadInBackground(new GetDataCallback() {
                       @Override
                       public void done(byte[] data, ParseException e) {
                         Log.i("ParseImageView",
                             "Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
                       }


                 });
                }
    }//for loop
            });


        query1.findInBackground(new FindCallback<ParseUser>() {

            public void done(List<ParseUser> userlistname, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < userlistname.size(); i++) {
                        names.add(userlistname.get(i).get("Name").toString());
                    }
                    usersListView = (ListView) getActivity().findViewById(
                            R.id.userlistname);
                    namesArrayAdapter = new ArrayAdapter<String>(getActivity()
                            .getApplicationContext(), R.layout.user_list_item,
                            names);
                    usersListView.setAdapter(namesArrayAdapter);

                    usersListView
                            .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> a,
                                                        View v, int i, long l) {
                                    openConversation(names, i);
                                }
                            });

                } else {
                    Toast.makeText(getActivity().getApplicationContext(),
                            "Error loading user list", Toast.LENGTH_LONG)
                            .show();
                }
                }
            });


            query11.findInBackground(new FindCallback<ParseUser>() {

            public void done(List<ParseUser> userlistheadline, ParseException e) {
                if (e == null) {
                    for (int i = 0; i < userlistheadline.size(); i++) {
                        headline.add(userlistheadline.get(i).get("Headline")
                                .toString());
                    }
                    usersListView = (ListView) getActivity().findViewById(
                            R.id.userlistheadline);
                    namesArrayAdapter = new ArrayAdapter<String>(getActivity()
                            .getApplicationContext(), R.layout.user_list_all,
                            headline);
                    usersListView.setAdapter(namesArrayAdapter);

                    usersListView
                            .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> a,
                                                        View v, int i, long l) {
                                    openConversation(names, i);
                                }
                            });

                } else {
                    Toast.makeText(getActivity().getApplicationContext(),
                            "Error loading user list", Toast.LENGTH_LONG)
                            .show();
                }
            }
        });

    }

    public void openConversation(ArrayList<String> names, int pos) {
        ParseQuery<ParseUser> query = ParseUser.getQuery();
        query.whereEqualTo("Name", names.get(pos));
        query.findInBackground(new FindCallback<ParseUser>() {
            public void done(List<ParseUser> user, ParseException e) {
                if (e == null) {
                    Intent intent = new Intent(getActivity()
                            .getApplicationContext(), MessagingActivity.class);
                    intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
                    startActivity(intent);
                } else {
                    Toast.makeText(getActivity().getApplicationContext(),
                            "Error finding that user", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        });
    }

}

下面是XML布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bac_blue"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/userlistname"
        android:layout_width="220dp"
        android:layout_centerHorizontal="true"
        android:layout_height="50dp"
        android:divider="@null"

        >

    </ListView>

    <ListView
        android:id="@+id/userlistheadline"
        android:layout_width="220dp"
        android:layout_below="@+id/userlistname"
        android:layout_centerHorizontal="true"
        android:layout_height="50dp"
        android:divider="@null"

        >

    </ListView>

     <ImageView
        android:id="@+id/profilePictureresult"
        android:layout_width="132dp"
        android:layout_height="120dp"
        android:layout_below="@+id/userlistheadline"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="7dp"
        android:layout_marginBottom="9dp"
        android:padding="3dp"
        android:scaleType="centerCrop"
        android:cropToPadding="true"
        android:background="@drawable/border_image"
        android:alpha="1" />

    <ListView
        android:id="@+id/userlistage"
        android:layout_width="220dp"
        android:layout_below="@+id/profilePictureresult"
        android:layout_centerHorizontal="true"
        android:layout_height="50dp"
        android:divider="@null"

        >

    </ListView>

     <ListView
        android:id="@+id/userlistactivityname"
        android:layout_width="220dp"
        android:layout_below="@+id/profilePictureresult"
        android:layout_centerHorizontal="true"
        android:layout_height="50dp"
        android:divider="@null"

        >

    </ListView>


    <Button
        android:id="@+id/button1"
        android:layout_below="@+id/userlistactivityname"
        android:layout_centerHorizontal="true"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_marginTop="12dp"
        android:alpha="0.7"
        android:textColor="#000000"
        android:background="#ADD8E6"
        android:textSize="22sp"
        android:typeface="serif"
        android:text="Confirm" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="70dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/imageView1"
        android:alpha="0.7"
        android:src="@drawable/left_right" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="70dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@+id/userlistview"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="119dp"
        android:alpha="0.7"
        android:src="@drawable/left_arrow2" />

</RelativeLayout>

任何帮助将不胜感激。

收到更新logcat消息

08-23 11:42:32.291: E/AndroidRuntime(1283): FATAL EXCEPTION: main
08-23 11:42:32.291: E/AndroidRuntime(1283): Process: com.dooba.beta, PID: 1283
08-23 11:42:32.291: E/AndroidRuntime(1283): java.lang.ClassCastException: android.widget.ImageView cannot be cast to com.parse.ParseImageView
08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.dooba.beta.Fragment1$1.done(Fragment1.java:174)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.parse.FindCallback.internalDone(FindCallback.java:45)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.parse.FindCallback.internalDone(FindCallback.java:1)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.parse.Parse$6$1.run(Parse.java:888)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.os.Handler.handleCallback(Handler.java:733)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.os.Handler.dispatchMessage(Handler.java:95)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.os.Looper.loop(Looper.java:136)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at android.app.ActivityThread.main(ActivityThread.java:5017)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at java.lang.reflect.Method.invokeNative(Native Method)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at java.lang.reflect.Method.invoke(Method.java:515)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
08-23 11:42:32.291: E/AndroidRuntime(1283):     at dalvik.system.NativeStart.main(Native Method)
08-23 13:25:28.269: E/AndroidRuntime(1377): FATAL EXCEPTION: main
08-23 13:25:28.269: E/AndroidRuntime(1377): Process: com.dooba.beta, PID: 1377
08-23 13:25:28.269: E/AndroidRuntime(1377): java.lang.NullPointerException
08-23 13:25:28.269: E/AndroidRuntime(1377):     at com.dooba.beta.Fragment1$1$1.done(Fragment1.java:184)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at com.parse.ParseImageView$1.done(ParseImageView.java:157)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at com.parse.GetDataCallback.internalDone(GetDataCallback.java:20)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at com.parse.GetDataCallback.internalDone(GetDataCallback.java:1)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at com.parse.Parse$6$1.run(Parse.java:888)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at android.os.Handler.handleCallback(Handler.java:733)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at android.os.Handler.dispatchMessage(Handler.java:95)
08-23 13:25:28.269: E/AndroidRuntime(1377):     at android.os.Looper.loop(Looper.java:136)

更新2 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bac_blue"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_below="@+id/userlistactivityname"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="28dp"
        android:alpha="0.7"
        android:background="#ADD8E6"
        android:text="Confirm"
        android:textColor="#000000"
        android:textSize="22sp"
        android:typeface="serif" />

    <ListView
        android:id="@+id/userlistage"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_below="@+id/profilePictureresult"
        android:layout_marginTop="19dp"
        android:layout_toLeftOf="@+id/imageView2"
        android:divider="@null" >
    </ListView>

    <com.parse.ParseImageView
        android:id="@+id/profilePictureresult"
        android:layout_width="132dp"
        android:layout_height="120dp"
        android:layout_below="@+id/userlistheadline"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="17dp"
        android:alpha="1"
        android:background="@drawable/border_image"
        android:cropToPadding="true"
        android:padding="3dp"
        android:scaleType="centerCrop" />

    <ListView
        android:id="@+id/userlistname"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="25dp"
        android:layout_toRightOf="@+id/imageView1"
        android:divider="@null" >
    </ListView>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="70dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/profilePictureresult"
        android:layout_marginTop="16dp"
        android:alpha="0.7"
        android:src="@drawable/left_right" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="70dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/imageView2"
        android:alpha="0.7"
        android:src="@drawable/left_arrow2" />

    <ListView
        android:id="@+id/userlistheadline"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_below="@+id/userlistname"
        android:layout_marginTop="17dp"
        android:layout_toRightOf="@+id/imageView1"
        android:divider="@null" >
    </ListView>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/userlistage"
        android:layout_centerHorizontal="true"
        android:text="Activity Name"
        android:textColor="#a2a2a2"
        android:textSize="22sp" />

    <ListView
        android:id="@+id/userlistactivityname"
        android:layout_width="220dp"
        android:layout_height="50dp"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="7dp"
        android:layout_toLeftOf="@+id/imageView2"
        android:divider="@null" >
    </ListView>

</RelativeLayout>

===============>>#1 票数:1

您必须在布局文件中使用像这样的ParseImageView

<com.parse.ParseImageView
        android:id="@+id/profilePictureresult"
        android:layout_width="132dp"
        android:layout_height="120dp"
        android:layout_below="@+id/userlistheadline"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="7dp"
        android:layout_marginBottom="9dp"
        android:padding="3dp"
        android:scaleType="centerCrop"
        android:cropToPadding="true"
        android:background="@drawable/border_image"
        android:alpha="1" />

  ask by user3827788 translate from so

未解决问题?本站智能推荐:

2回复

在文本视图上显示来自Parse的信息

我试图根据有关解析的信息在文本视图中显示文本。 例如,在这种情况下,我试图显示用户的活动名称。 下面是代码 布局 下面是完整的代码 如果您需要其他信息,请告诉我。
1回复

从ListView到TextView(解析)

在支持下,我设法从解析中检索列表和图像,但是,我希望能够检索可以在textview中显示为与listview相反的字符串,因为在我检索一个项目时没有理由使用列表。 此外,我的问题是列表视图在触摸时可以滚动,因此我想如果它只是一个文本视图会更好。 下面是检索列表视图的代码,我希望能够在文本
1回复

在null对象引用上对'android.support.v7.widget.RecyclerView $ LayoutManager'的任何解决方案

我一直试图解决这个问题,过去10天我无法解决这个问题。 我已经使用parse sdk为我的应用程序,我能够从解析服务器检索但没有它崩溃与此错误。 java.lang.NullPointerException: Attempt to invoke virtual method void an
2回复

无法将ProfilePictureView强制转换为android.widget.ImageView

启动以下活动时,我的应用程序意外崩溃。 基本上,在此活动中,用户可以从Facebook上传他们的图片,并将个人资料图片投射到imageview。 我在日志猫消息下面包括了以下内容: 以下是活动代码: } 下面是布局代码:
1回复

LinearLayout无法强制转换为android.widget.ImageView?

在我的listView中我试图设置我的imageView所以我可以显示每行的唯一图像,但我得到这个错误: - 我的CustomAdapter.java类,我假设问题是,看起来像这样: 最后这里是我的list_row.xml,其中有问题的视图位于: 此外,当我查看我的错误
2回复

无法将Textview强制转换为android.widget.listview

我相信具有textview,但是在下面的以下代码中不能将其强制转换为listview错误:本质上,我试图将信息从Parse填充到文本字段中。 我相信这是有问题的代码部分。 在这里它抛出“无法将textview强制转换为android.widget.listview” 下面是XML
1回复

NullPointerException-ParseImageView

尝试从Parse检索信息(例如字符串,数字和图像)时,收到以下错误:特别是,我从ParseImageView接收到错误,在该位置可以很好地检索字符串和数字。 日志消息 XML布局 活动代码 提前致谢 更新:
1回复

无法将Android.widget.RelativeLayout强制转换为android.widget.ImageView

我正在尝试获取XML布局文件中定义的ImageView的实例: 但是我总是会遇到运行时错误: 行“ 57”是这样的: 我不知道为什么会抛出这个错误。 我看不到这段代码的问题。 还有人知道吗? 谢谢FelixD。
3回复

无法解析com.parse.ParseQueryAdapter

我目前的设置: 操作系统:Windows 7 IDE:Android Studio(带有更新的SDK) 解析罐(v 1.10) 我正在尝试ParseQueryAdapter的一个例子,我在我的IDE上遇到了这个错误: import com.parse.Parse
1回复

无法解析为变量-Parse.com

我正在尝试从解析中检索信息。 特别是,我添加了一个条件,该条件仅返回选择了相同活动的用户列表。 这样做时,我意外收到以下错误: 从本质上讲,它将看到哪些用户选择了该特定活动名称并返回,我随机添加了此变量,因为我想检索选择了该活动的用户名列表(当前用户除外)。 我不想特别指出一个用户