0

我在应用程序中使用 TimesSquare 日历库。当我尝试打开课程时遇到问题,我收到以下错误:

android.view.InflateException: Binary XML file line #3: Error inflating class library.MonthView

我尝试重新启动 Eclipse,使用导入再次添加库并创建一个新项目,但没有奏效。这是日志的其余部分:

    10-27 05:39:59.675: E/AndroidRuntime(401): FATAL EXCEPTION: main
10-27 05:39:59.675: E/AndroidRuntime(401): android.view.InflateException: Binary XML file line #3: Error inflating class library.MonthView
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-27 05:39:59.675: E/AndroidRuntime(401):  at com.squareup.timessquare.MonthView.create(MonthView.java:21)
10-27 05:39:59.675: E/AndroidRuntime(401):  at com.squareup.timessquare.CalendarPickerView$MonthAdapter.getView(CalendarPickerView.java:493)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.AbsListView.obtainView(AbsListView.java:1315)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.ListView.makeAndAddView(ListView.java:1727)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.ListView.fillDown(ListView.java:652)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.ListView.fillFromTop(ListView.java:709)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.ListView.layoutChildren(ListView.java:1566)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.AbsListView.onLayout(AbsListView.java:1147)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.View.layout(View.java:7035)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.View.layout(View.java:7035)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.View.layout(View.java:7035)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.View.layout(View.java:7035)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.os.Looper.loop(Looper.java:123)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.app.ActivityThread.main(ActivityThread.java:4627)
10-27 05:39:59.675: E/AndroidRuntime(401):  at java.lang.reflect.Method.invokeNative(Native Method)
10-27 05:39:59.675: E/AndroidRuntime(401):  at java.lang.reflect.Method.invoke(Method.java:521)
10-27 05:39:59.675: E/AndroidRuntime(401):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-27 05:39:59.675: E/AndroidRuntime(401):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-27 05:39:59.675: E/AndroidRuntime(401):  at dalvik.system.NativeStart.main(Native Method)
10-27 05:39:59.675: E/AndroidRuntime(401): Caused by: java.lang.ClassNotFoundException: library.MonthView in loader dalvik.system.PathClassLoader[/data/app/khs.studentsupport-2.apk]
10-27 05:39:59.675: E/AndroidRuntime(401):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-27 05:39:59.675: E/AndroidRuntime(401):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-27 05:39:59.675: E/AndroidRuntime(401):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.LayoutInflater.createView(LayoutInflater.java:466)
10-27 05:39:59.675: E/AndroidRuntime(401):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
10-27 05:39:59.675: E/AndroidRuntime(401):  ... 29 more

我正在使用的类目前与示例代码中包含的类完全相同。http://corner.squareup.com/2013/01/times-square.html

SampleTimesSquareActivity

public class SampleTimesSquareActivity extends Activity {
    private static final String TAG = "SampleTimesSquareActivity";
    private CalendarPickerView calendar;

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

        final Calendar nextYear = Calendar.getInstance();
        nextYear.add(Calendar.YEAR, 1);

        final Calendar lastYear = Calendar.getInstance();
        lastYear.add(Calendar.YEAR, -1);

        calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
        calendar.init(lastYear.getTime(), nextYear.getTime()) //
                .inMode(SelectionMode.SINGLE) //
                .withSelectedDate(new Date());

        final Button single = (Button) findViewById(R.id.button_single);
        final Button multi = (Button) findViewById(R.id.button_multi);
        final Button range = (Button) findViewById(R.id.button_range);
        final Button dialog = (Button) findViewById(R.id.button_dialog);
        single.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                single.setEnabled(false);
                multi.setEnabled(true);
                range.setEnabled(true);

                calendar.init(new Date(), nextYear.getTime()) //
                        .inMode(SelectionMode.SINGLE) //
                        .withSelectedDate(new Date());
            }
        });

        multi.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                single.setEnabled(true);
                multi.setEnabled(false);
                range.setEnabled(true);

                Calendar today = Calendar.getInstance();
                ArrayList<Date> dates = new ArrayList<Date>();
                for (int i = 0; i < 5; i++) {
                    today.add(Calendar.DAY_OF_MONTH, 3);
                    dates.add(today.getTime());
                }
                calendar.init(new Date(), nextYear.getTime()) //
                        .inMode(SelectionMode.MULTIPLE) //
                        .withSelectedDates(dates);
            }
        });

        range.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                single.setEnabled(true);
                multi.setEnabled(true);
                range.setEnabled(false);

                Calendar today = Calendar.getInstance();
                ArrayList<Date> dates = new ArrayList<Date>();
                today.add(Calendar.DATE, 3);
                dates.add(today.getTime());
                today.add(Calendar.DATE, 5);
                dates.add(today.getTime());
                calendar.init(new Date(), nextYear.getTime()) //
                        .inMode(SelectionMode.RANGE) //
                        .withSelectedDates(dates);
            }
        });

        dialog.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                CalendarPickerView dialogView = (CalendarPickerView) getLayoutInflater()
                        .inflate(R.layout.dialog, null, false);
                dialogView.init(new Date(), nextYear.getTime());
                new AlertDialog.Builder(SampleTimesSquareActivity.this)
                        .setTitle("I'm a dialog!")
                        .setView(dialogView)
                        .setNeutralButton("Dismiss",
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(
                                            DialogInterface dialogInterface,
                                            int i) {
                                        dialogInterface.dismiss();
                                    }
                                }).create().show();
            }
        });

        findViewById(R.id.done_button).setOnClickListener(
                new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Log.d(TAG, "Selected time in millis: "
                                + calendar.getSelectedDate().getTime());
                        String toast = "Selected: "
                                + calendar.getSelectedDate().getTime();
                        Toast.makeText(SampleTimesSquareActivity.this, toast,
                                LENGTH_SHORT).show();
                    }
                });
    }

xml布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button_single"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Single"
            android:enabled="false"/>

        <Button
            android:id="@+id/button_multi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Multi" />

        <Button
            android:id="@+id/button_range"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Range" />

      <Button
          android:id="@+id/button_dialog"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Dialog" />

    </LinearLayout>

  <com.squareup.timessquare.CalendarPickerView
      android:id="@+id/calendar_view"
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:paddingLeft="16dp"
      android:paddingRight="16dp"
      android:paddingBottom="16dp"
      android:scrollbarStyle="outsideOverlay"
      android:clipToPadding="false"
      android:background="#FFFFFF"
      />
  <Button
      android:id="@+id/done_button"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Done"
      />

</LinearLayout>

有谁知道这里发生了什么?我在网上环顾四周,似乎无法用其他建议解决这个问题。

4

1 回答 1

1

这是一个已知问题,已在 1.1.1-SNAPSHOT 版本中修复https://github.com/square/android-times-square/issues/106

于 2014-02-07T17:23:11.720 回答