1

アプリケーションの XML レイアウト側にいくつかの変更を加えています。私が前に持ってこようとしている ImageView がありますが、アプリがクラッシュすると、その理由がわかるようです。

作業中の 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="wrap_content" >

<TextView
    android:id="@+id/place_distance"
    android:layout_width="wrap_content"
    android:layout_height="14dip"
    android:layout_alignParentRight="true"
    android:layout_gravity="right"
    android:layout_margin="5dip"
    android:gravity="right"
    android:text="28-12-1920 22:22"
    android:textColor="@color/white"
    android:textSize="12sp" />

<ImageView
    android:id="@+id/place_img"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_margin="5dp"
    android:scaleType="centerCrop"
    android:src="@drawable/icon_4860_1" />

<LinearLayout
    android:id="@+id/wrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/place_img"
    android:layout_alignRight="@+id/place_distance"
    android:layout_below="@+id/place_distance"
    android:layout_marginTop="5dp"
    android:background="@drawable/chatbox" >

    <TextView
        android:id="@+id/comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="43dp"
        android:padding="9dp"
        android:paddingLeft="10dip"
        android:text="Hello bubbles!"
        android:textColor="@android:color/white"
        android:textColorLink="@android:color/holo_blue_dark"
        android:textIsSelectable="true" />
</LinearLayout>

<TextView
    android:id="@+id/place_name"
    android:textIsSelectable="true"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/place_distance"
    android:layout_toLeftOf="@+id/place_distance"
    android:layout_toRightOf="@+id/place_img"
    android:text="Tweeked"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/gray"
    android:textSize="11dp"
    android:textStyle="bold" />

<ImageView
    android:id="@+id/pe_profile_pic"
    android:layout_width="10dp"
    android:layout_height="10dp"
    android:layout_margin="2dp"
    android:layout_alignBottom="@+id/place_img"
    android:layout_alignRight="@+id/place_img"

    android:src="@drawable/offline" />

クラッシュする 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="wrap_content" >

<TextView
    android:id="@+id/place_distance"
    android:layout_width="wrap_content"
    android:layout_height="14dip"
    android:layout_alignParentRight="true"
    android:layout_gravity="right"
    android:layout_margin="5dip"
    android:gravity="right"
    android:text="28-12-1920 22:22"
    android:textColor="@color/white"
    android:textSize="12sp" />

<LinearLayout
    android:id="@+id/wrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/place_img"
    android:layout_alignRight="@+id/place_distance"
    android:layout_below="@+id/place_distance"
    android:layout_marginTop="5dp"
    android:background="@drawable/chatbox" >

    <TextView
        android:id="@+id/comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="43dp"
        android:padding="9dp"
        android:paddingLeft="10dip"
        android:text="Hello bubbles!"
        android:textColor="@android:color/white"
        android:textColorLink="@android:color/holo_blue_dark"
        android:textIsSelectable="true" />

    <!-- android:autoLink="web|all" -->

</LinearLayout>

<ImageView
    android:id="@+id/place_img"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_margin="5dp"
    android:scaleType="centerCrop"
    android:src="@drawable/icon_4860_1" />

<TextView
    android:id="@+id/place_name"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/place_distance"
    android:layout_toLeftOf="@+id/place_distance"
    android:text="Tweeked"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/gray"
    android:textIsSelectable="true"
    android:textSize="11dp"
    android:textStyle="bold" />

<ImageView
    android:id="@+id/pe_profile_pic"
    android:layout_width="10dp"
    android:layout_height="10dp"
    android:layout_alignBottom="@+id/place_img"
    android:layout_alignRight="@+id/place_img"
    android:layout_margin="2dp"
    android:src="@drawable/offline" />

@place_img を @wrapper の前に持っていこうとしているだけです。

java.lang.NullPointerException at com.peekatucorp.peekatu.DiscussArrayAdapter.getView(DiscussArrayAdapter.java:172)

ディスカッションArrayAdapter.java:

        public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if (row == null) {
        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if(type==1 || type==3)
            row = inflater.inflate(R.layout.listitem_discuss, parent, false);
        else if(type==4 || type==5)
            row = inflater.inflate(R.layout.listitem_users, parent, false);
        else
            row = inflater.inflate(R.layout.listitem_messages, parent, false);
    }

//  

    final OneComment coment = getItem(position);

    userComment = (TextView) row.findViewById(R.id.comment);
    userImage = (ImageView) row.findViewById(R.id.place_img);
    userName = (TextView) row.findViewById(R.id.place_name);
    userOnlineImage = (ImageView) row.findViewById(R.id.pe_profile_pic);
    commentDate = (TextView) row.findViewById(R.id.place_distance);

    userComment.setText(coment.comment);

    ImageLoader imageLoader = ImageLoader.getInstance();
//  imageLoader = ImageLoader.getInstance();
//  imageLoader.init(ImageLoaderConfiguration.createDefault(convertView.getContext()));

    imageLoader.displayImage(coment.image, userImage);
    userImage.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // it was the 1st button


             final TabInfo tab = navact.getCurrentTabInfo();
                final ProfileFragment fragment = new ProfileFragment().setUser(coment.userid).setNAV(navact);
              //  fragment.setText(characters[position]);

                // second, you push the fragment. It becomes visible and the up button is
                // shown
                navact.pushFragment(tab, fragment);

             /*
             Intent i = new Intent(context, ProfileActivity.class);

             i.putExtra("userID", coment.userid);

             // Create the view using FirstGroup's LocalActivityManager
             View view = ChatTabGroup.group.getLocalActivityManager()
             .startActivity("show profile", i
             .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
             .getDecorView();

             // Again, replace the view
             ChatTabGroup.group.replaceView(view);*/

          }
        });
    if(coment.online.equalsIgnoreCase("1"))
    userOnlineImage.setImageResource(R.drawable.online);
    else
    userOnlineImage.setImageResource(R.drawable.offline);
    if(coment.gender.equalsIgnoreCase("M"))
        userName.setTextColor(Color.parseColor("#878ff4"));
    else if(coment.gender.equalsIgnoreCase("F"))
        userName.setTextColor(Color.parseColor("#f487d6"));
    else
        userName.setTextColor(Color.parseColor("#969696"));
    userName.setText(coment.username);

    commentDate.setText(coment.time);
    if(type==4){
        commentDate = (TextView) row.findViewById(R.id.textView1);
        SharedPreferences preferences = getContext().getSharedPreferences("MyPreferences", getContext().MODE_PRIVATE);
    double distance = distFrom(Double.parseDouble(getItem(position).time.split(",")[0]),Double.parseDouble(getItem(position).time.split(",")[1]),
            Double.parseDouble(preferences.getString("user_lat", "0.0")),Double.parseDouble(preferences.getString("user_lng", "0.0"))
            );
    commentDate.setText(""+String.format("%.2f", (distance*0.62))+"miles");
    }

    if(type==1 || type==3){
        wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
        wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);
    }else{      



    }
//    

    return row;
}

ありがとうございました。

4

1 に答える 1

0
<?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="wrap_content" >

<TextView
    android:id="@+id/place_distance"
    android:layout_width="wrap_content"
    android:layout_height="14dip"
    android:layout_alignParentRight="true"
    android:layout_gravity="right"
    android:layout_margin="5dip"
    android:gravity="right"
    android:text="28-12-1920 22:22"
    android:textColor="@color/white"
    android:textSize="12sp" />

<LinearLayout
    android:id="@+id/wrapper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/place_img"
    android:layout_alignRight="@+id/place_distance"
    android:layout_below="@+id/place_distance"
    android:layout_marginTop="5dp"
    android:background="@drawable/chatbox" >

    <TextView
        android:id="@+id/comment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="43dp"
        android:padding="9dp"
        android:paddingLeft="10dip"
        android:text="Hello bubbles!"
        android:textColor="@android:color/white"
        android:textColorLink="@android:color/holo_blue_dark"
        android:textIsSelectable="true"
        android:typeface="serif" 
        android:autoLink="web|all"
        />

    <!-- android:autoLink="web|all" -->

</LinearLayout>

<ImageView
    android:id="@+id/place_img"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_margin="5dp"
    android:scaleType="centerCrop"
    android:src="@drawable/icon_4860_1" />

<ImageView
    android:id="@+id/pe_profile_pic"
    android:layout_width="10dp"
    android:layout_height="10dp"
    android:layout_alignBottom="@+id/place_img"
    android:layout_alignRight="@+id/place_img"
    android:layout_margin="2dp"
    android:src="@drawable/offline" />

<TextView
    android:id="@+id/place_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/wrapper"
    android:layout_toRightOf="@+id/place_img"
    android:text="Tweeked"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/gray"
    android:textIsSelectable="true"
    android:textSize="14sp"
    android:textStyle="bold"
    android:typeface="normal" />

于 2013-09-02T04:29:19.423 に答える