Question

I have a soundboard which works in Android OSes until ICS. There is a TabHost which has tabs added to it dynamically, each tab having a different ScrollView created by a new TabContentFactory.

When it comes to add the tab, it spits this out into the log that a ResourceNotFoundException was thrown. I don't think I'm missing any resources, since it works fine on all but ICS.

I'm including the log and relevant code. Is there anything else that would help narrow down the problem?

The log: ...

2012-07-08 16:26:53.507 E 7979/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lysolpionex.HomestarRunnerSoundboard/com.lysolpionex.HomestarRunnerSoundboard.HomestarRunnerSoundboardActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
    at android.app.ActivityThread.access$600(ActivityThread.java:139)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:5008)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1105)
    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2344)
    at android.content.res.Resources.getLayout(Resources.java:944)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at android.widget.TabHost$LabelAndIconIndicatorStrategy.createIndicatorView(TabHost.java:579)
    at android.widget.TabHost.addTab(TabHost.java:227)
...

The code to create my tabhost, add tabs to it etc. is:

private ViewGroup createTABForm() {
    //construct the TAB host
    TabHost tabHost = new TabHost(this);
    tabHost.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


    //the tabHost needs a tabWidget, a container for the visible tabs
    TabWidget tabWidget = new TabWidget(this);
    tabWidget.setId(android.R.id.tabs);
    HorizontalScrollView horizScrollView = new HorizontalScrollView(this);
    horizScrollView.addView(tabWidget);
    tabHost.addView(horizScrollView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    //the tabHost needs a frameLayout for the views associated with each visible tab
    FrameLayout frameLayout = new FrameLayout(this);
    frameLayout.setId(android.R.id.tabcontent);
    frameLayout.setPadding(0, 100, 0, 0);
    tabHost.addView(frameLayout, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    //call setup, since it's not initialized in XML
    tabHost.setup();

    /*-----------------*
     * set up the tabs *
     *-----------------*/
    Iterator<String> namesItr = characters.getNamesItr();
    Iterator<Drawable> drawableItr = characters.getDrawableItr();

    String name = null; //the current character's name
    final Context context = this;
    while(namesItr.hasNext()){  //iterate over all the characters
        name = namesItr.next();   //get this character's name
        final Drawable drawable = drawableItr.next();//the current character's icon
        final String finalName = name;  //silly final variable to satisfy compiler

        //set up the icons
        TabHost.TabSpec tabSpec = tabHost.newTabSpec(name+" Tab");
        tabSpec.setIndicator(name, drawable);

        tabSpec.setContent(new TabHost.TabContentFactory() {

            @Override
            public ScrollView createTabContent(String tag) {
                LinearLayout panel = new LinearLayout(HomestarRunnerSoundboardActivity.this);
                panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
                panel.setOrientation(LinearLayout.VERTICAL);

                //iterate over all the sounds for this character
                Iterator<String> titlesItr = characters.getTitlesItrForChar(finalName);
                Iterator<Integer> idsItr = characters.getIDsItrForChar(finalName);
                String title = null;

                while(titlesItr.hasNext() && idsItr.hasNext()){
                    title = titlesItr.next();

                    final Button button = new Button(HomestarRunnerSoundboardActivity.this);
                    button.setText(title);
                    button.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                    button.setGravity(Gravity.CENTER);
                    final String finalTitle = title;
                    final int finalID = idsItr.next();

                    button.setOnClickListener(new View.OnClickListener(){
                        @Override
                        public void onClick(View v) {
                            SoundManager.playSound(finalTitle);
                        }
                    });

                    /*---------------------------------------------------------------------------
                     * Sets the long-click action, in this case to save a sound and set it as a *
                     * ringtone/notification                                                    *
                     *--------------------------------------------------------------------------*/
                    button.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View v) {
                        //save the file to the sd card
                        if(setFileAsRingAndNotifSound(finalID, finalTitle)){
                            Toast.makeText(HomestarRunnerSoundboardActivity.this, "Sound added to ringtones/alerts", Toast.LENGTH_SHORT).show();
                        }
                        else{
                            Toast.makeText(HomestarRunnerSoundboardActivity.this, "Error adding sound to ringtones/alerts", Toast.LENGTH_LONG).show();
                            Log.e(Utils.hsrTAG, "Error setting file as ringtone/notification sound.");
                        }
                        return true;
                      }
                    });
                    button.setMinWidth(m_nScreenW); //do I need this?
                    panel.addView(button);
                }

                ScrollView scrollView = new ScrollView(context);
                scrollView.addView(panel);

                return scrollView;
            }
        });

        tabHost.addTab(tabSpec);
    }

    return tabHost;
}

No correct solution

OTHER TIPS

I have the same problem, but bit different, searching inside stackoverflow I found this: I think it can help you

Honeycomb and TabHost specs

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top