English 中文(简体)
java.lang.Illegal ArgumentException: 目标不得取消
原标题:java.lang.IllegalArgumentException: Target must not be null

当我向皮索传递图像时,我发现我的错误“目标决不能取消”。 当我用皮卡索用尿素图像时,我发现我的错误。 甚至我对图像的id也正确。 最后,我用静态形象代替了图像ur,尽管我也遇到同样的错误。

我的守则是:

public class MainScreen extends AppCompatActivity {

private ImageView user_profile_pic,img2;
private ImageView like_button,dislike_button,location_button,refresh;

private ArrayList<String> al;
private ArrayAdapter<String> arrayAdapter;
private int i;

private SwipeFlingAdapterView flingContainer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);


    //Setting
    user_profile_pic=(ImageView)findViewById(R.id.profile_image);
    img2=(ImageView)findViewById(R.id.img2);

    //Picasso.with(getApplicationContext()).load("https://pbs.twimg.com/profile_images/596282530652753921/bPf8NmOs.jpg").into(user_profile_pic);

    //Picasso.with(getApplicationContext()).load(android.R.drawable.btn_star).into(img);


    Picasso.with(getApplicationContext()).load("https://pbs.twimg.com/profile_images/596282530652753921/bPf8NmOs.jpg")
            .placeholder(android.R.drawable.btn_star)
            .error(android.R.drawable.btn_star)
           .into(img2);


    flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);

    al = new ArrayList<>();
    al.add("php");
    al.add("c");
    al.add("python");
    al.add("java");
    al.add("html");
    al.add("c++");
    al.add("css");
    al.add("javascript");

    arrayAdapter = new ArrayAdapter<>(this, R.layout.custom_user_details, R.id.helloText, al );

    flingContainer.setAdapter(arrayAdapter);

    flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
        @Override
        public void removeFirstObjectInAdapter() {

            Log.d("LIST", "removed object!");
            al.remove(0);
            arrayAdapter.notifyDataSetChanged();
        }

        @Override
        public void onLeftCardExit(Object dataObject) {

            Toast.makeText(getApplicationContext(),"Left !",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRightCardExit(Object dataObject) {

            Toast.makeText(getApplicationContext(),"Right !",Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onAdapterAboutToEmpty(int itemsInAdapter) {

            al.add("XML ".concat(String.valueOf(i)));
            arrayAdapter.notifyDataSetChanged();
            Log.d("LIST", "notified");
            i++;
        }

        @Override
        public void onScroll(float scrollProgressPercent) {

            try
            {
                View view = flingContainer.getSelectedView();
                view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercent < 0 ? -scrollProgressPercent : 0);
                view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0);
            }
            catch (NullPointerException e) {
                Log.e("tag", "NullPointerException" + e);
            }

        }
    });

    //flingContainer.getTopCardListener().selectRight(); To remove view from right side while pressing button

}

@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_main_screen, 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);
}

}

这也是我的智慧:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="80">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/img2"
                android:src="@android:drawable/btn_star"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="20"
            android:padding="8dp"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Vimal, "
                    android:id="@+id/helloText"
                    android:textColor="@android:color/black"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="23"
                    android:textColor="@android:color/black"
                    android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:orientation="horizontal">


                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_weight="1">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@android:drawable/btn_dialog"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0"
                        android:textSize="25sp"
                        android:layout_marginLeft="5dp"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                        android:gravity="center"/>

                </LinearLayout>


                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_weight="1">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:src="@android:drawable/btn_dialog"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="0"
                        android:textSize="25sp"
                        android:layout_marginLeft="5dp"
                        android:layout_gravity="center"
                        android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

                </LinearLayout>

            </LinearLayout>


        </LinearLayout>




    </LinearLayout>

    <View
        android:id="@+id/item_swipe_left_indicator"
        android:alpha="0"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="10dp"
        android:background="#A5F" />

    <View
        android:id="@+id/item_swipe_right_indicator"
        android:alpha="0"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="10dp"
        android:layout_gravity="right"
        android:background="#5AF" />

</FrameLayout>
问题回答

<代码>img2为无效,并将之转至<条码>功能。

img2 = (ImageView)findViewById(R.id.img2);之后添加一个无效的核对表,以检查何时停止无效,或者在你重新测试期间是否中止,或者仅仅确认其无效。

检查您的布局,并确保他们重新获得所有组合的权利,并确保您有<条码>@+id/img2。 页: 1

你们是否确实装上正确的布局? 因为在 Java档案中,你有R.id.profile_image,但I don t发现,在你的Xml档案中,这种id。

You can t download image from https using Picasso library. you can use this library.

试图改变它。

Picasso.with(MainScreen.this).load("https://pbs.twimg.com/profile_images/596282530652753921/bPf8NmOs.jpg")
            .placeholder(android.R.drawable.btn_star)
            .error(android.R.drawable.btn_star)
           .into(img2);

还确保你使用<代码>活性_main_ Screen.xml布局,如果是,则检查该阴道。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签