[英]Importing a view in xml layout
我正在嘗試在我正在制作的應用程序中使用AndroidQuickResponseCode 。 但是我很難找到一個在我自己的應用程序中運行的示例。
我已將問題縮小到布局文件中的一個引用,它說:
<com.jwetherell.quick_response_code.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/transparent">
</com.jwetherell.quick_response_code.ViewfinderView>
當它嘗試在布局中呈現 com.jwetherell.quick_response_code.ViewfinderView 時出錯。 它應該能夠在我作為庫添加的 jar 文件中找到。 (它從那個 jar 中找到其他文件。)logcat 中的堆棧跟蹤相當長,但這些行對我來說似乎是一個摘要:
11-23 11:22:57.055: E/AndroidRuntime(12552): FATAL EXCEPTION: main
11-23 11:22:57.055: E/AndroidRuntime(12552): Process: se.tii.vargis, PID: 12552
11-23 11:22:57.055: E/AndroidRuntime(12552): java.lang.RuntimeException: Unable to start activity ComponentInfo{se.tii.vargis/se.tii.vargis.CaptureActivity}: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.jwetherell.quick_response_code.ViewfinderView
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: android.view.InflateException: Binary XML file line #26: Binary XML file line #26: Error inflating class com.jwetherell.quick_response_code.ViewfinderView
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class com.jwetherell.quick_response_code.ViewfinderView
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: java.lang.reflect.InvocationTargetException
11-23 11:22:57.055: E/AndroidRuntime(12552): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f04000d
這似乎意味着它找不到xml布局文件中寫入的com.jwetherell.quick_response_code.ViewfinderView。 有什么特殊的方法可以導入一些東西以便它可以在 xml 文件中使用嗎?
我的活動代碼是空的,它只用setContentView(R.layout.activity_capture);
設置布局setContentView(R.layout.activity_capture);
看到你必須在你的項目中創建一個與https://github.com/phishman3579/android-quick-response-code/blob/master/src/com/jwetherell/quick_response_code/ViewfinderView.java相同的類
然后在 xml 文件中,您必須提供該文件的路徑,因為您的包名稱是“com.example.SampleHello”+您的類名“ViewfinderView”,因此您的 xml 將是這樣的
<com.example.SampleHello.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/transparent">
</com.example.SampleHello.ViewfinderView>
將鼠標指針指向 ViewfinderView 並單擊 ctrl + 單擊然后 ViewfinderView 類打開意味着它正在獲取類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.