SlidingUpPanel崩溃

时间:2014-05-22 03:59:49

标签: java android eclipse android-fragments android-library

我想在我的主要活动中使用Umano/SlidingUpPanel

这是我的activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DemoActivity" >

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/lib/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:panelHeight="68dp"
        sothree:shadowHeight="4dp"
        sothree:paralaxOffset="100dp"
        sothree:dragView="@+id/name">

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="?android:attr/actionBarSize">
            <Button
        android:id="@+id/bigbutton_right"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignBaseline="@+id/bigbutton_middle"
        android:layout_alignBottom="@+id/bigbutton_middle"
        android:layout_marginLeft="7dp"
        android:layout_toRightOf="@+id/bigbutton_middle"
        android:onClick="selectFrag"
        android:background="@drawable/mainbutton_right" />

    <Button
        android:id="@+id/bigbutton_left"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:onClick="selectFrag"
        android:layout_alignBaseline="@+id/bigbutton_middle"
        android:layout_alignBottom="@+id/bigbutton_middle"
        android:layout_marginRight="7dp"
        android:layout_toLeftOf="@+id/bigbutton_middle"
        android:background="@drawable/mainbutton_left" />

      <Button
          android:id="@+id/bigbutton_middle"
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="138dp"
          android:background="@drawable/mainbutton_middle"
          android:onClick="selectFrag" />
       <fragment
          android:id="@+id/fragment_place"
          android:name="com.mainpackage.FragmentOne"
          android:layout_width="match_parent"
          android:layout_height="340dp"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/bigbutton_right"
          android:layout_marginTop="14dp" />
            <TextView
                android:id="@+id/main"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="Main Content"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:textSize="16sp" />            
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#eeeeee"
            android:orientation="vertical"
            android:clickable="true"
            android:focusable="false">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/name"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:textSize="14sp"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"/>

                <Button
                    android:id="@+id/follow"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="14sp"
                    android:gravity="center_vertical|right"
                    android:paddingRight="10dp"
                    android:paddingLeft="10dp"/>

            </LinearLayout>



        </LinearLayout>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>

这是我的MainActivity.java

package com.mainpackage;



import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;


public class MainActivity extends Activity {
int t=1;
int oldt=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);


      requestWindowFeature(Window.FEATURE_NO_TITLE);


      setContentView(R.layout.activity_main);

     one=(Button)findViewById(R.id.bigbutton_left);
     two=(Button)findViewById(R.id.bigbutton_middle);
      three=(Button)findViewById(R.id.bigbutton_right);
      one.setBackgroundResource(R.drawable.button_full_gen_pressed);

    }
    Button one;
    Button two;
    Button three;

    public void selectFrag(View view) {
         Fragment fr;

         one.setBackgroundResource(R.drawable.button_full_gen_normal);
         two.setBackgroundResource(R.drawable.button_chap_gen_normal);
         three.setBackgroundResource(R.drawable.button_ncert_normal);

         if(view == findViewById(R.id.bigbutton_middle)) {
             fr = new FragmentTwo();             
             t=2;
             two.setBackgroundResource(R.drawable.button_chap_gen_pressed);

         }else if(view==findViewById(R.id.bigbutton_right)) {
             fr = new FragmentThree();
             t=3;
             three.setBackgroundResource(R.drawable.button_ncert_pressed);
         }
         else {
             one.setBackgroundResource(R.drawable.button_full_gen_pressed)      ;    

             t=1;
             fr=new FragmentOne();
         }
         FragmentManager fm = getFragmentManager();
         FragmentTransaction fragmentTransaction = fm.beginTransaction();



         if(oldt!=t)
         {  fragmentTransaction.setCustomAnimations(R.anim.slide_in, R.anim.slide_out);
         oldt=t;
         }
         else
         {
             fragmentTransaction.setCustomAnimations(R.anim.none, R.anim.none);
         }
         fragmentTransaction.replace(R.id.fragment_place, fr);
         fragmentTransaction.commit();

    }

}

当我编译时,代码编译,但它崩溃了以下错误代码:

  
    

05-22 08:57:12.884:E / AndroidRuntime(4126):FATAL EXCEPTION:main 05-22 08:57:12.884:E / AndroidRuntime(4126):     java.lang.RuntimeException:无法启动活动     ComponentInfo {com.mainpackage / com.mainpackage.MainActivity}:     android.view.InflateException:二进制XML文件行#6:错误     inflating class com.sothree.slidinguppanel.SlidingUpPanelLayout 05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     android.app.ActivityThread.access $ 600(ActivityThread.java:123)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     android.os.Handler.dispatchMessage(Handler.java:99)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.os.Looper.loop(Looper.java:137)05-22 08:57:12.884:     E / AndroidRuntime(4126):at     android.app.ActivityThread.main(ActivityThread.java:4424)05-22     08:57:12.884:E / AndroidRuntime(4126):at     java.lang.reflect.Method.invokeNative(Native Method)05-22     08:57:12.884:E / AndroidRuntime(4126):at     java.lang.reflect.Method.invoke(Method.java:511)05-22 08:57:12.884:     E / AndroidRuntime(4126):at     com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:825)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)05-22     08:57:12.884:E / AndroidRuntime(4126):at     dalvik.system.NativeStart.main(Native Method)05-22 08:57:12.884:     E / AndroidRuntime(4126):引起:android.view.InflateException:     二进制XML文件行#6:错误类膨胀     com.sothree.slidinguppanel.SlidingUpPanelLayout 05-22 08:57:12.884:     E / AndroidRuntime(4126):at     android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     android.view.LayoutInflater.rInflate(LayoutInflater.java:739)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.view.LayoutInflater.inflate(LayoutInflater.java:489)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.view.LayoutInflater.inflate(LayoutInflater.java:396)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.view.LayoutInflater.inflate(LayoutInflater.java:352)05-22     08:57:12.884:E / AndroidRuntime(4126):at     com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     android.app.Activity.setContentView(Activity.java:1835)05-22     08:57:12.884:E / AndroidRuntime(4126):at     com.mainpackage.MainActivity.onCreate(MainActivity.java:26)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.app.Activity.performCreate(Activity.java:4465)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1051)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)     05-22 08:57:12.884:E / AndroidRuntime(4126):... 11更多05-22     08:57:12.884:E / AndroidRuntime(4126):引起:     抛出java.lang.ClassNotFoundException:     com.sothree.slidinguppanel.SlidingUpPanelLayout 05-22 08:57:12.884:     E / AndroidRuntime(4126):at     dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)     05-22 08:57:12.884:E / AndroidRuntime(4126):at     java.lang.ClassLoader.loadClass(ClassLoader.java:501)05-22     08:57:12.884:E / AndroidRuntime(4126):at     java.lang.ClassLoader.loadClass(ClassLoader.java:461)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.view.LayoutInflater.createView(LayoutInflater.java:552)05-22     08:57:12.884:E / AndroidRuntime(4126):at     android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)

  

我做错了什么?

2 个答案:

答案 0 :(得分:2)

谢谢大家。 问题非常简单,我没有将图书馆标记为图书馆项目。 我做到了,并将它添加到我自己的项目的构建路径中,并且它可以工作。

答案 1 :(得分:0)

您是否添加了jar文件或在工作区中处理了整个源代码。使用自定义视图时问题似乎在这一行:<com.sothree.slidinguppanel.SlidingUpPanelLayou
确保SlidingUpPanelLayout只有两个孩子......

导入库时,请确保使用自定义视图的名称。它必须匹配。检查它