Repository: rey5137/material

Issue #219: Spinner java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Created: 2015-08-16T14:10:29Z
I'm trying to use com.rey.material.widget.Spinner in a fragment but I'm getting the following error when I try to change spinner value. Could you please help me with the issue. Thank you for your time.
Here is the code and error
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.rey.material.widget.Spinner;
public class SpinnerFragment extends Fragment {
View SpinV;

String items[] = {"Choose type of vehicle","Car","Bus","Two wheeler","Lorry","Other"};
Spinner spn_label;

public SpinnerFragment() {
    // Required empty public constructor
}

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

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    if(SpinV==null) {
        SpinV = inflater.inflate(R.layout.fragment_spinns, container, false);
    }
    spn_label = (Spinner)SpinV.findViewById(R.id.spinner_label);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.row_spn, items);
    adapter.setDropDownViewResource(R.layout.row_spn_dropdown);
    spn_label.setAdapter(adapter);

    return SpinV;
}

}
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3881)
at android.view.ViewGroup.addView(ViewGroup.java:3734)
at android.view.ViewGroup.addView(ViewGroup.java:3679)
at android.view.ViewGroup.addView(ViewGroup.java:3655)
at com.rey.material.widget.Spinner.onDataInvalidated(Spinner.java:927)
at com.rey.material.widget.Spinner.setSelection(Spinner.java:422)
at com.rey.material.widget.Spinner.performItemClick(Spinner.java:898)
at com.rey.material.widget.Spinner$DropdownPopup$3.onItemClick(Spinner.java:1271)
at com.rey.material.widget.Spinner$DropDownAdapter.onClick(Spinner.java:1140)
at com.rey.material.widget.RippleManager.run(RippleManager.java:100)
at com.rey.material.widget.RippleManager.onClick(RippleManager.java:93)
at android.view.View.performClick(View.java:4759)
at android.view.View$PerformClick.run(View.java:19770)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5232)
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:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

Duplicate issue #265: Crash app when i use Snipper
Created: 2015-09-27T12:44:33Z
i give this error
09-27 16:11:09.041    9217-9217/ir.parsidev.android.mastercharge E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.parsidev.android.mastercharge/ir.parsidev.android.mastercharge.DepositActivity}: android.view.InflateException: Binary XML file line #80: Error inflating class com.rey.material.widget.Spinner
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
            at android.app.ActivityThread.access$600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4441)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #80: Error inflating class com.rey.material.widget.Spinner
            at android.view.LayoutInflater.createView(LayoutInflater.java:606)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:255)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at ir.parsidev.android.mastercharge.DepositActivity.onCreate(DepositActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:4465)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
            at android.app.ActivityThread.access$600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4441)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:586)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:255)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at ir.parsidev.android.mastercharge.DepositActivity.onCreate(DepositActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:4465)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
            at android.app.ActivityThread.access$600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4441)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoSuchFieldError: com.rey.material.R$styleable.Spinner_prompt
            at com.rey.material.widget.Spinner.applyStyle(Spinner.java:234)
            at com.rey.material.widget.Spinner.init(Spinner.java:154)
            at com.rey.material.widget.Spinner.<init>(Spinner.java:136)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:586)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:255)
            at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
            at ir.parsidev.android.mastercharge.DepositActivity.onCreate(DepositActivity.java:25)
            at android.app.Activity.performCreate(Activity.java:4465)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
            at android.app.ActivityThread.access$600(ActivityThread.java:127)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4441)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
            at dalvik.system.NativeStart.main(Native Method)

i use this in xml
<com.rey.material.widget.Spinner
                    android:id="@+id/PaymentMethodDeposit"
                    style="@style/Material.Widget.Spinner"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="13dp"
                    app:rd_delayClick="none"
                    app:rd_enable="true"
                    app:rd_style="@style/Material.Drawable.Ripple.Wave"
                    app:spn_arrowAnimDuration="@android:integer/config_shortAnimTime"
                    app:spn_arrowInterpolator="@android:anim/decelerate_interpolator"
                    app:spn_arrowSwitchMode="true"
                    app:spn_label="Spinner with arrow"
                    app:spn_labelEnable="true" />

and this in Activity
String[] items = new String[20];
        for(int i = 0; i < items.length; i++)
            items[i] = "Item " + String.valueOf(i + 1);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(DepositActivity.this, R.layout.row_spn, items);
        spPaymentMethod.setAdapter(adapter);

Closing comment (2015-10-01T20:11:39Z): Duplicate of #219