按下微调器时应用程序崩溃

时间:2016-09-01 04:28:49

标签: java android xml drop-down-menu spinner

每当我按下下拉列表meal_array和drop_ array时,应用程序崩溃。我该如何解决这个问题?我已经发布了XML文件和Java文件以及错误日志。

XML文件

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/cal"

        android:textSize="20sp"
        android:layout_marginTop="20dp"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="OR"
    android:textSize="20sp"
    android:id="@+id/or"
    android:layout_below="@+id/cal"
    android:layout_alignRight="@+id/drop"
    android:layout_alignEnd="@+id/drop"
    android:layout_marginTop="10dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="You can also select differnet calorie intake according to your choice."
        android:layout_below="@+id/or"
        android:id="@+id/opt"
        android:textSize="20sp"
        style="@style/TextColor"
        android:layout_marginTop="10dp"
        />

    <TextView
        style="@style/TextColor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingTop="16dp"
        android:text="Calorie Intake in a day."
        android:textSize="20sp"
        android:id="@+id/drop"
        android:layout_below="@id/opt"/>

<Spinner
    android:id="@+id/drop_spinner"
    style="@style/SpinnerCustomTheme"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_below="@id/drop"
    android:entries="@array/drop_array" />

<TextView
    style="@style/TextColor"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:paddingTop="16dp"
    android:text="Nuber of meals you would want to have in a day."
    android:textSize="20sp"
    android:id="@+id/meal"
    android:layout_below="@id/drop_spinner"/>

<Spinner
    android:id="@+id/meal_spinner"
    style="@style/SpinnerCustomTheme"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/meal"
    android:entries="@array/meal_array" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text=""
    style="@style/TextColor"
    android:id="@+id/amount"
    android:layout_below="@+id/meal_spinner"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/subs"
    android:layout_below="@+id/amount"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp"
    android:text="Pay Now"
    style="@style/ButtonCustomTheme"/>

Java文件

package tiphinbox.main;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
public class Customization extends AppCompatActivity {
Spinner spinneruse,drop;
TextView price;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_customization);
    Bundle extras = getIntent().getExtras();
    TextView tv = (TextView) findViewById(R.id.cal);
    tv.setText(extras.getString("Message"));
    drop = (Spinner) findViewById(R.id.drop_spinner);
    price= (TextView) findViewById(R.id.amount);
    spinneruse = (Spinner) findViewById(R.id.meal_spinner);
    spinneruse.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            switch (i) {
                case 0:
                    price.setText("Final Amount to be paid is Rs.4,500");
                    break;
                case 1:
                    price.setText("Final Amount to be paid is Rs.3,700");
                    break;
                case 2:
                    price.setText("Final Amount to be paid is Rs.3,200");
                    break;
                case 3:
                    price.setText("Final Amount to be paid is Rs.2,500");
                    break;
                default:
                    break;
            }
        }
        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}
}

错误记录

E/AndroidRuntime: FATAL EXCEPTION: main
Process: tiphinbox.main, PID: 3349
android.view.InflateException: Binary XML file line #19: Failed to resolve attribute at index 6: TypedValue{t=0x1c/d=0xff33b5e5 a=1 r=0x1060012}
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378)
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448)
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963)
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959)
at android.widget.Spinner.measureContentWidth(Spinner.java:833)
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220)
at android.widget.Spinner.performClick(Spinner.java:758)
at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:441)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 6: TypedValue{t=0x1c/d=0xff33b5e5 a=1 r=0x1060012}
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:705)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6890)
at android.view.ViewGroup$LayoutParams.<init>(ViewGroup.java:6842)
at android.view.ViewGroup.generateLayoutParams(ViewGroup.java:5779)
at android.view.LayoutInflater.inflate(LayoutInflater.java:502)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:378) 
at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:448) 
at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:963) 
at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:959) 
at android.widget.Spinner.measureContentWidth(Spinner.java:833) 
at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1194) 
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1220) 
at android.widget.Spinner.performClick(Spinner.java:758) 
at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:441) 
at android.view.View$PerformClick.run(View.java:21147) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method)

SpinnerCustomTheme

<style name="SpinnerCustomTheme"           parent="android:Widget.Holo.Light.Spinner">
    <item     name="android:background">@drawable/customtheme_spinner_background_holo_light</item>
    <item    name="android:dropDownSelector">@drawable/customtheme_list_selector_holo_light</item>
</style>

customtheme_spinner_background_holo_light

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/customtheme_spinner_disabled_holo_light" android:state_enabled="false" />
<item android:drawable="@drawable/customtheme_spinner_pressed_holo_light" android:state_pressed="true" />
<item android:drawable="@drawable/customtheme_spinner_focused_holo_light" android:state_focused="true" android:state_pressed="false" />
<item android:drawable="@drawable/customtheme_spinner_default_holo_light" />

自定义主题列表选择器     

<item android:drawable="@android:color/transparent" android:state_window_focused="false" />

<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:drawable="@drawable/customtheme_list_selector_disabled_holo_light" android:state_enabled="false" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@drawable/customtheme_list_selector_disabled_holo_light" android:state_enabled="false" android:state_focused="true" />
<item android:drawable="@drawable/customtheme_list_selector_background_transition_holo_light" android:state_focused="true" android:state_pressed="true" />
<item android:drawable="@drawable/customtheme_list_selector_background_transition_holo_light" android:state_focused="false" android:state_pressed="true" />
<item android:drawable="@drawable/customtheme_list_focused_holo" android:state_focused="true" />

0 个答案:

没有答案