开发者

Problem with Android Hello Tab Widget Example

I'm trying to implement the 'tab layout' example from the Android SDK tutorials here: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

I noticed that lots of people have encountered problems in implementing this.I think I read all the possible links on google/stackoverflow and tried/checked everything but still can't make it work. I still keep on getting the error "The application Hello Tab Widget stopped unexpectedly. Please try again." at launch.

I've uploaded my entire project here (Android 2.3.3): https://www.yousendit.com/download/VnBxak85UnFCSnF4dnc9PQ

Also, here's the manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.kaushal.hellotabwidget"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".hellotabwidget"
                  android:label="@string/app_name">
             <!--       android:theme="@android:style/Theme.NoTitleBar">-->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".AlbumsActivity"></activity> 
        <activity android:name=".ArtistsActivity"></activity> 
        <activity android:name=".SongsActivity"></activity> 
    </application>
</manifest>

And the HelloTabWidget.java file,

package com.kaushal.hellotabwidget;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

public class HelloTabWidget extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, ArtistsActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("artists").setIndicator("Artists",
                          res.getDrawable(R.drawable.ic_tab_artists))
                      .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, AlbumsActivity.class);
        spec = tabHost.newTabSpec("albums").setIndicator("Albums",
                          res.getDrawable(R.drawable.ic_tab_albums))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, SongsActivity.class);
        spec = tabHost.newTabSpec("songs").setIndicator("Songs",
                          res.getDrawable(R.drawable.ic_tab_songs))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);

    }
}

And a sample logcat when the app launches,

    04-25 13:10:42.105 D/AndroidRuntime(  671): 
        04-25 13:10:42.105 D/AndroidRuntime(  671): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
        04-25 13:10:42.105 D/AndroidRuntime(  671): CheckJNI is ON
        04-25 13:10:43.135 D/AndroidRuntime(  671): Calling main entry com.android.commands.pm.Pm
        04-25 13:10:43.195 D/AndroidRuntime(  671): Shutting down VM
        04-25 13:10:43.215 I/AndroidRuntime(  671): NOTE: attach of thread 'Binder Thread #3' failed
        04-25 13:10:43.215 D/dalvikvm(  671): GC_CONCURRENT freed 100K, 72% free 296K/1024K, external 0K/0K, paused 3ms+5ms
        04-25 13:10:43.225 D/jdwp    (  671): adbd disconnected
        04-25 13:10:43.975 D/AndroidRuntime(  681): 
        04-25 13:10:43.975 D/AndroidRuntime(  681): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
        04-25 13:10:43.975 D/AndroidRuntime(  681): CheckJNI is ON
        04-25 13:10:45.065 D/AndroidRuntime(  681): Calling main entry com.android.commands.am.Am
        04-25 13:10:45.135 I/ActivityManager(   67): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.kaushal.hellotabwidget/.hellotabwidget } from pid 681
        04-25 13:10:45.205 D/AndroidRuntime(  681): Shutting down VM
        04-25 13:10:45.285 I/AndroidRuntime(  681): NOTE: attach of thread 'Binder Thread #3' failed
        04-25 13:10:45.315 D/dalvikvm(  681): GC_CONCURRENT freed 101K, 69% free 318K/1024K, external 0K/0K, paused 3ms+84ms
        04-25 13:10:45.385 D/jdwp    (  681): adbd disconnected
        04-25 13:10:45.456 I/ActivityManager(   67): Start proc com.kaushal.hellotabwidget for activity com.kaushal.hellotabwidget/.hellotabwidget: pid=690 uid=10037 gids={1015}
        04-25 13:10:46.815 D/AndroidRuntime(  690): Shutting down VM
        04-25 13:10:46.815 W/dalvikvm(  690): threadid=1: thread exiting with uncaught exception (group=0x40015560)
        04-25 13:10:46.845 E/AndroidRuntime(  690): FATAL EXCEPTION: main
        04-25 13:10:46.845 E/AndroidRuntime(  690): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.kaushal.hellotabwidget/com.kaushal.hellotabwidget.hellotabwidget}: java.lang.ClassNotFoundException: com.kaushal.hellotabwidget.hellotabwidget in loader dalvik.system.PathClassLoader[/data/app/com.kaushal.hellotabwidget-2.apk]
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.os.Handler.dispatchMessage(Handler.java:99)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.os.Looper.loop(Looper.java:123)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.ActivityThread.main(ActivityThread.java:3683)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at java.lang.reflect.Method.invokeNative(Native Method)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at java.lang.reflect.Method.invoke(Method.java:507)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at dalvik.system.NativeStart.main(Native Method)
        04-25 13:10:46.845 E/AndroidRuntime(  690): Caused by: java.lang.ClassNotFoundException: com.kaushal.hellotabwidget.hellotabwidget in loader dalvik.system.PathClassLoader[/data/app/com.kaushal.hellotabwidget-2.apk]
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
        04-25 开发者_如何学运维13:10:46.845 E/AndroidRuntime(  690):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
        04-25 13:10:46.845 E/AndroidRuntime(  690):     ... 11 more
        04-25 13:10:46.855 W/ActivityManager(   67):   Force finishing activity com.kaushal.hellotabwidget/.hellotabwidget
        04-25 13:10:47.375 W/ActivityManager(   67): Activity pause timeout for HistoryRecord{40745f70 com.kaushal.hellotabwidget/.hellotabwidget}
        04-25 13:10:58.235 W/ActivityManager(   67): Activity destroy timeout for HistoryRecord{40745f70 com.kaushal.hellotabwidget/.hellotabwidget}
        04-25 13:11:05.205 D/dalvikvm(   67): GC_CONCURRENT freed 515K, 42% free 4437K/7623K, external 884K/1297K, paused 10ms+10ms
        0

Please let me know what I'm doing wrong here. Have been trying to figure this out for more than a day now but can't make it work.

This is my first posting to Stackoverflow. Please forgive me if I missed any rules of the posting:). Thanks all for your help in advance.


In your Manifest, replace:

<activity android:name=".hellotabwidget"

with:

<activity android:name=".HelloTabWidget"

Activity names are case sensitive (they are class names after all).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜