2012-08-29 5 views
2

탭을 사용하여 Bluetooth, Wi-Fi, 전화 통화 및 SMS를 구현하는 응용 프로그램을 구축하고 있습니다. MainActivity.java 파일은 아래와 같습니다.탭을 사용하는 응용 프로그램 충돌이 발생했습니다.

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 파일을 만들었습니다 (나중에 더 많은 코드를 작성합니다).

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 오류가 아래에 나와 있습니다. 내가 전에하지만이 경우 내가 활동 클래스를 확장하지 않은 탭에 표시하려고 한 클래스 중 하나에 비슷한 문제가 발생했습니다

 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 

는 (그게 내가이 사용자에 대해 들었다 무엇 이었습니까) .

내 이전 질문과 관련하여 여기에 a link이 있습니다.

하지만 지금은 Activity 클래스를 확장 한 모든 클래스를 사용 했으므로 런타임 중에 문제가 없어야합니다. 도와주세요

답변

0

당신은 wifispec.setContent()를 사용했습니다; 전화 사용 callspec.setContent (callIntent);

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);** 
+0

감사합니다. 그것은 실수였다. 나는 바보로 만들었다. – UselessNoob

+0

귀하의 환영에 감사드립니다. @ 마난 – erkuy

관련 문제