1

我正在尝试将 csipsimple 重用为库。并调用同一个库中存在的 ui

我的 xml 文件看起来像

<LinearLayout 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=".DialerActivity" >

    <view 
        class="com.csipsimple.widgets.Dialpad"
        android:id="@+id/dialPad"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:paddingBottom="10dip"
        android:paddingLeft="5dip"
        android:paddingRight="5dip" />

</LinearLayout>

我从中调用的活动

package com.*****.payphone;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class DialerActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_dialer, menu);
        return true;
    }

}

和堆栈跟踪相同的是我不明白我做错了什么

03-28 18:52:18.847: I/ActivityThread(16221): Pub com.csipsimple.db: com.csipsimple.db.DBProvider
03-28 18:52:18.870: D/dalvikvm(16221): GC_CONCURRENT freed 152K, 2% free 9116K/9296K, paused 8ms+6ms, total 71ms
03-28 18:52:18.894: V/DummySetUp(16206):  <sip:****@*****.net> IwYzK5IbKJv8DQT 1
03-28 18:52:18.956: D/AndroidRuntime(16206): Shutting down VM
03-28 18:52:18.956: W/dalvikvm(16206): threadid=1: thread exiting with uncaught exception (group=0x41f27930)
03-28 18:52:18.964: E/AndroidRuntime(16206): FATAL EXCEPTION: main
03-28 18:52:18.964: E/AndroidRuntime(16206): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.novanet.payphone/com.*****.payphone.DialerActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class com.csipsimple.widgets.Dialpad
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.os.Looper.loop(Looper.java:137)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.ActivityThread.main(ActivityThread.java:5039)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at java.lang.reflect.Method.invokeNative(Native Method)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at java.lang.reflect.Method.invoke(Method.java:511)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at dalvik.system.NativeStart.main(Native Method)
03-28 18:52:18.964: E/AndroidRuntime(16206): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.csipsimple.widgets.Dialpad
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.Activity.setContentView(Activity.java:1881)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at com.novanet.payphone.DialerActivity.onCreate(DialerActivity.java:12)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.Activity.performCreate(Activity.java:5104)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-28 18:52:18.964: E/AndroidRuntime(16206):    ... 11 more
03-28 18:52:18.964: E/AndroidRuntime(16206): Caused by: java.lang.reflect.InvocationTargetException
03-28 18:52:18.964: E/AndroidRuntime(16206):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-28 18:52:18.964: E/AndroidRuntime(16206):    ... 22 more
03-28 18:52:18.964: E/AndroidRuntime(16206): Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class android.widget.ImageButton
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.inflate(LayoutInflater.java:459)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at com.csipsimple.widgets.Dialpad.<init>(Dialpad.java:105)
03-28 18:52:18.964: E/AndroidRuntime(16206):    ... 25 more
03-28 18:52:18.964: E/AndroidRuntime(16206): Caused by: java.lang.reflect.InvocationTargetException
03-28 18:52:18.964: E/AndroidRuntime(16206):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-28 18:52:18.964: E/AndroidRuntime(16206):    ... 33 more
03-28 18:52:18.964: E/AndroidRuntime(16206): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000f a=2}
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.content.res.Resources.loadDrawable(Resources.java:1927)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.view.View.<init>(View.java:3328)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.widget.ImageView.<init>(ImageView.java:114)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.widget.ImageButton.<init>(ImageButton.java:87)
03-28 18:52:18.964: E/AndroidRuntime(16206):    at android.widget.ImageButton.<init>(ImageButton.java:83)
03-28 18:52:18.964: E/AndroidRuntime(16206):    ... 36 more

我的图书馆项目在我的主要项目之外,它位于 com 包中。* .payphone 和正在使用的图书馆项目是 com.csipsimple.widget.Dialpad

4

3 回答 3

2

你试过用<com.csipsimple.widgets.Dialpad而不是

 <view 
        class="com.csipsimple.widgets.Dialpad"

?

于 2013-03-28T15:33:29.553 回答
1

您应该在 XML 中定义您的自定义视图,如下所示:

<com.csipsimple.widgets.Dialpad
    android:id="@+id/dialPad"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:paddingBottom="10dip"
    android:paddingLeft="5dip"
    android:paddingRight="5dip" />
于 2013-03-28T15:34:29.650 回答
0

确保您的主题扩展了 ActionBarSherlock 主题之一。拨号盘按钮使用 ABS 的背景。看到这个类似的问题

于 2014-06-04T19:41:08.000 回答