问题描述
我想在我的Android应用程序创建一个搜索查看,遗憾的是,几乎所有的例子是有关在动作条实施搜索查看。我禁用了动作条,我想创建一个线性布局内搜索查看。
I'm trying to create a SearchView in my android app, unfortunately almost all examples are about implementing the searchview in the actionbar. I have disabled the actionbar and I want to create the searchview inside a linear layout.
所以我放在搜索查看了里面的LinearLayout,只要你做的XML preVIEW将显示渲染问题:
so I placed the searchview inside the linearlayout, as soon as you do that the xml preview will show "Rendering Problems":
java.lang.NullPointerException
at android.content.res.TypedArray.hasValueOrEmpty(TypedArray.java:845)
at android.widget.SearchView.<init>(SearchView.java:295)
at android.widget.SearchView.<init>(SearchView.java:258)
at android.widget.SearchView.<init>(SearchView.java:254)
at sun.reflect.GeneratedConstructorAccessor499.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:82)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:128)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:410)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:708)
at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:697)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:697)
at com.android.tools.idea.rendering.RenderService.render(RenderService.java:816)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:646)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:589)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:584)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
但是当我运行它工作得很好的应用,任何想法,这是为什么NullPointerException异常被抛出?
but when I run the application it works just fine, any idea why is this nullpointerexception have been thrown?
这是我的XML code:
this is my xml code:
<SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/searchView"
android:iconifiedByDefault="false"
android:queryHint="Search"
android:searchIcon="@drawable/search_icon"
>
</SearchView>
和可以请你给我提供了如何从实例化的Java文件这个搜索查看这样我就可以使用它的一些例子code?
and can you please provide me some example code on how to instantiate this searchview from java file so I can use it?
推荐答案
的 NullPointerException异常
是由IDE(而不是应用程序),当它试图使甩在搜索查看
。似乎没有要与查看
本身这样的问题。如果您的应用程序工作正常,那么就忽略它。
The NullPointerException
is thrown by the IDE (not the application) when it tries to render the SearchView
. There doesn't seem to be a problem with the View
itself as such. If your app is working correctly, then just ignore it.
这篇关于搜索查看无动作条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!