- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试修改 Android API 演示 16 中的 Tabs1.java
(并在 API 16 模拟器上运行)以使用标准 Activity
而不是已弃用的TabActivity
类(class)。我创建了一个新的布局文件并修改了代码。
我尝试使用这种方法而不是操作栏的原因是选项卡不适用于整个屏幕,仅适用于较小的 subview 。
当我执行代码时,在执行以下行时,我在 Android setContent
方法中得到了一个NullPointerException
:
tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(R.id.view1)
知道为什么会发生这种情况吗?完整的堆栈跟踪在代码和布局之后。
Tabs1VanillaActivity.java
:
public class Tabs1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs1);
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1")
.setContent(R.id.view1));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab2")
.setContent(R.id.view2));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("tab3")
.setContent(R.id.view3));
}
}
tabs1.xml:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView goes here!"
tools:ignore="HardcodedText" />
<TabHost
android:id="@+id/tabhost"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blue"
android:text="@string/tabs_1_tab_1" />
<TextView
android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/red"
android:text="@string/tabs_1_tab_2" />
<TextView
android:id="@+id/view3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/green"
android:text="@string/tabs_1_tab_3" />
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
堆栈跟踪:
09-18 16:18:22.968: E/AndroidRuntime(1191): FATAL EXCEPTION: main
09-18 16:18:22.968: E/AndroidRuntime(1191): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.apis/com.example.android.apis.view.Tabs1}: java.lang.NullPointerException
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.os.Looper.loop(Looper.java:137)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-18 16:18:22.968: E/AndroidRuntime(1191): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 16:18:22.968: E/AndroidRuntime(1191): at java.lang.reflect.Method.invoke(Method.java:511)
09-18 16:18:22.968: E/AndroidRuntime(1191): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-18 16:18:22.968: E/AndroidRuntime(1191): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-18 16:18:22.968: E/AndroidRuntime(1191): at dalvik.system.NativeStart.main(Native Method)
09-18 16:18:22.968: E/AndroidRuntime(1191): Caused by: java.lang.NullPointerException
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.widget.TabHost$ViewIdContentStrategy.<init>(TabHost.java:617)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.widget.TabHost$ViewIdContentStrategy.<init>(TabHost.java:612)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.widget.TabHost$TabSpec.setContent(TabHost.java:461)
09-18 16:18:22.968: E/AndroidRuntime(1191): at com.example.android.apis.view.Tabs1.onCreate(Tabs1.java:42)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.Activity.performCreate(Activity.java:4465)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-18 16:18:22.968: E/AndroidRuntime(1191): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-18 16:18:22.968: E/AndroidRuntime(1191): ... 11 more
最佳答案
在尝试添加选项卡之前,您必须调用 tabHost.setup()
。
http://developer.android.com/reference/android/widget/TabHost.html#setup()
关于android - 布局中定义的 TabHost 在 setContent 期间给出 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12481045/
如果我在文本区域中预加载了内容,那么我会将新行转换为“br”标签。 但是,如果我尝试使用其 setContent 函数将内容动态设置(而不是粘贴)到tinymce textarea,则会丢失新行。 我
我正在开发一个带有选项卡式布局的 Android 应用程序。我已经把它带到了它不会产生像 Google's tutorial suggested 这样的新 Activity 的地方。 ,但是我这样做只
我有一个应用程序需要使用 QWebView::setContent()将一些 HTML 内容加载到 QWebView。所有这一切都发生在带有 ARMv5 处理器(想想 400 MHz)的嵌入式设备上。
我有tinymce,它工作正常,但setcontent仅在加载一次后才起作用(它没有内容),但在关闭并重新打开它后,它就带有内容了。 JS: tinymce.remove(); tinymce
当执行应用程序时,例如,JFrame 被实例化并填充一些内容;如果最终用户随后做出一些选择来重新填充 JFrame 的内容面板,程序员是否应该确保在添加新选择的内容之前删除原始内容,或者这并不重要?
我正在尝试在页面加载时设置一些文本编辑器的内容。我对 TinyMCE 不是很熟悉,稍微继承了代码。这是我初始化编辑器的方式 - tinyMCE.init({ // Genera
在 tinyMCE 插件(版本 3)上设置内容()后,如果用户更改了一些小的东西,例如该文本 block 的格式,下一个撤消步骤将清除整个文本 block 只是清除格式更改。 有没有人遇到过这种情况?
PHP/C#/ASP 编码器在给 Xamarin 一个镜头后正确地开始在 android 中(然后有 6 个月的中断所有编码)。 我正在尝试在通知中实现自定义布局。我可以让它产生正常的通知,但是当它使
我有一个选项卡 Activity ,它的每个选项卡都调用相同的 Activity 让我们说 MyTabInterface。所以我希望我的 MyTabInterface 可以获取按下哪个选项卡的信息。我
我已经坚持了几个小时,希望得到一些帮助。我正在使用 tinyMCE与 syntaxhl插件使用 syntaxhighlighter 2.1.382. 非高亮代码一切正常。但是,当使用带有突出显示代码的
button.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){
我正在尝试将函数 setContent 与 QuillJS 一起使用。 当我使用 JSON.stringify 将内容保存到数据库时,它看起来像这样: {"ops":[{"insert":"\n \n
我正在尝试使用 将一些额外的隐藏内容添加到tinymce编辑器中 tinyMCE.get('addCustom_id').setContent(data); 一旦在事件上执行上述行,setConten
我知道这个主题已经在这里讨论过很多次,但无论我采用哪种方法,我要么收到一个错误,例如“无法获取未定义或空引用的属性'setContent'”,要么该行执行但没有任何反应。 这是我所知道的。tinymc
我在表单中使用了 angular tinyMCE 指令。提交后,我使用此命令清除文本区域: tinyMCE.activeEditor.setContent(''); 还有这个:$scope.tinym
我想将一些 html 放入 tiptap 编辑器中,因为我想编辑我之前保存的内容。但是如果我里面有一些内联样式,tiptap 会删除它。有人知道我可以用它做什么吗? this.editor.setCo
过去,我已经使用以下代码成功淡入 NSWindow; if (![statusWindow isVisible]) { statusWindow.alphaValue = 0.0; [stat
我正在开发一个开源产品,以允许在 CMS 中进行协作编辑。用例如下:当用户 A 编辑某个小节点时,用户 B 更新同一节点。除了保留光标位置之外,更新用户的小型编辑器一切正常。 IE。 var book
问题是我想在 GridPane 和 Tab 之间传输项目所以我首先将该项目添加到选项卡中。 然后我将相同的项目添加到 GridPane 中。直到这里它都运行良好。但是后来我想将该项目添加回选项卡并且我
在我正在开发的一个应用程序中,根据车辆的最后已知速度,我每 100 毫秒插值一次车辆的下一个位置,并将其绘制在 map 上。这会导致移动设备出现性能问题。 我们还使用 MarkerWithLabels
我是一名优秀的程序员,十分优秀!