1

私はICSまでAndroidOSで動作するサウンドボードを持っています。タブが動的に追加されたTabHostがあり、各タブには、新しいTabContentFactoryによって作成された異なるScrollViewがあります。

タブを追加する場合、ResourceNotFoundExceptionがスローされたログにこれを吐き出します。ICS以外のすべてで正常に機能するため、リソースが不足しているとは思いません。

ログと関連するコードを含めています。問題を絞り込むのに役立つものは他にありますか?

ログ:..。

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)
...

タブホストを作成したり、タブを追加したりするためのコードは次のとおりです。

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;
}
4

1 に答える 1

0

私は同じ問題を抱えていますが、少し異なります。stackoverflow内を検索してこれを見つけました:それはあなたを助けることができると思います

HoneycombとTabHostの仕様

于 2012-08-01T10:23:25.897 に答える