使用标签应用崩溃 [英] Application using Tabs Crashes

查看:206
本文介绍了使用标签应用崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立实施蓝牙,WiFi,手机通话和使用标签,短信的应用程序。该MainActivity.java文件如下所示。

I'm building an application implementing Bluetooth , Wifi , Phone call and Sms using tabs . The MainActivity.java file is shown below .

package com.example.servicesdemo;

import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.support.v4.app.NavUtils;

public class MainActivity extends TabActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TabHost tabHost = getTabHost();

    TabSpec btspec = tabHost.newTabSpec("Bluetooth");
    btspec.setIndicator("Bluetooth");
    Intent btIntent = new Intent(getBaseContext() , BtActivity.class);
    btspec.setContent(btIntent);

    TabSpec wifispec = tabHost.newTabSpec("Wifi");
    wifispec.setIndicator("Wifi");
    Intent wifiIntent = new Intent(getBaseContext(),WifiActivity.class);
    wifispec.setContent(wifiIntent);

    TabSpec callspec = tabHost.newTabSpec("Phone Call");
    callspec.setIndicator("Phone Call");
    Intent callIntent = new Intent(getBaseContext(),CallActivity.class);
    wifispec.setContent(callIntent);

    TabSpec smsspec = tabHost.newTabSpec("SMS");
    wifispec.setIndicator("SMS");
    Intent smsIntent = new Intent(getBaseContext(),SmsActivity.class);
    smsspec.setContent(smsIntent);

    tabHost.addTab(btspec);
    tabHost.addTab(wifispec);
    tabHost.addTab(callspec);

    tabHost.addTab(smsspec);
    tabHost.setCurrentTab(0);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}


}

我创建4 XML文件和4活动的文件(一个用于上述各项服务)。对于〔实施例中,我创建了蓝牙选项卡BtActivity.java文件,如下图所示(我会写更多code以后)。

I've created 4 XML files and 4 Activity files (one for each service mentioned above) . For exmaple , I've created a BtActivity.java file for the bluetooth tab , as shown below (I'll be writing more code later on) .

BtActivity.java

BtActivity.java

package com.example.servicesdemo;

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

public class BtActivity extends Activity{
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bt_layout);
}

}

现在,当我尝试运行它简单的应用程序崩溃。下面示出了LogCat中出错。

Now when I try to run the application it simply crashes . The LogCat error is shown below .

     08-29 10:44:33.810: D/AndroidRuntime(369): Shutting down VM
08-29 10:44:33.810: W/dalvikvm(369): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-29 10:44:33.830: E/AndroidRuntime(369): FATAL EXCEPTION: main
08-29 10:44:33.830: E/AndroidRuntime(369): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.servicesdemo/com.example.servicesdemo.MainActivity}: java.lang.IllegalArgumentException: you must specify a way to create the tab content
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.os.Looper.loop(Looper.java:130)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-29 10:44:33.830: E/AndroidRuntime(369):  at java.lang.reflect.Method.invokeNative(Native Method)
08-29 10:44:33.830: E/AndroidRuntime(369):  at java.lang.reflect.Method.invoke(Method.java:507)
08-29 10:44:33.830: E/AndroidRuntime(369):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-29 10:44:33.830: E/AndroidRuntime(369):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-29 10:44:33.830: E/AndroidRuntime(369):  at dalvik.system.NativeStart.main(Native Method)
08-29 10:44:33.830: E/AndroidRuntime(369): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab content
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.widget.TabHost.addTab(TabHost.java:202)
08-29 10:44:33.830: E/AndroidRuntime(369):  at com.example.servicesdemo.MainActivity.onCreate(MainActivity.java:43)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-29 10:44:33.830: E/AndroidRuntime(369):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-29 10:44:33.830: E/AndroidRuntime(369):  ... 11 more
08-29 10:49:53.781: D/AndroidRuntime(378): Shutting down VM
08-29 10:49:53.781: W/dalvikvm(378): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-29 10:49:53.790: E/AndroidRuntime(378): FATAL EXCEPTION: main
08-29 10:49:53.790: E/AndroidRuntime(378): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.servicesdemo/com.example.servicesdemo.MainActivity}: java.lang.IllegalArgumentException: you must specify a way to create the tab content
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.os.Looper.loop(Looper.java:130)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-29 10:49:53.790: E/AndroidRuntime(378):  at java.lang.reflect.Method.invokeNative(Native Method)
08-29 10:49:53.790: E/AndroidRuntime(378):  at java.lang.reflect.Method.invoke(Method.java:507)
08-29 10:49:53.790: E/AndroidRuntime(378):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-29 10:49:53.790: E/AndroidRuntime(378):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-29 10:49:53.790: E/AndroidRuntime(378):  at dalvik.system.NativeStart.main(Native Method)
08-29 10:49:53.790: E/AndroidRuntime(378): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab content
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.widget.TabHost.addTab(TabHost.java:202)
08-29 10:49:53.790: E/AndroidRuntime(378):  at com.example.servicesdemo.MainActivity.onCreate(MainActivity.java:43)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-29 10:49:53.790: E/AndroidRuntime(378):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-29 10:49:53.790: E/AndroidRuntime(378):  ... 11 more
08-29 10:49:56.110: I/Process(378): Sending signal. PID: 378 SIG: 9

我以前可是在那种情况下,我是想在一个标签,显示并没有延续Activity类的类的一个遇到了类似的问题(这是什么,我的用户告知)。

I've encountered a similar problem before but in that case one of the class which I was trying to display in a tab did not extend the Activity class (That was what I was told about by the users) .

下面的链接以供参考我的previous问题。

Here's a link to my previous question for reference .

但现在,我已经使用扩展Activity类的所有类,所以在运行时应该没有问题。请帮助

But now , I've used all classes extending the Activity class , so there should be no problem during runtime . Please help

推荐答案

您已经使用wifispec.setContent();对于电话呼叫使用callspec.setContent(callIntent);等等。

you have used wifispec.setContent(); for Phone Call use callspec.setContent(callIntent); etc.

TabSpec callspec = tabHost.newTabSpec("Phone Call");
    **callspec.setIndicator("Phone Call");** 
    Intent callIntent = new Intent(getBaseContext(),CallActivity.class);
    **wifispec.setContent(callIntent);**  ---> callspec.setContent(callIntent);

    TabSpec smsspec = tabHost.newTabSpec("SMS");
    **wifispec.setIndicator("SMS");**  ---> smsspec.setIndicator("SMS");
    Intent smsIntent = new Intent(getBaseContext(),SmsActivity.class);
    **smsspec.setContent(smsIntent);**   

这篇关于使用标签应用崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆