0

私のアプリケーションには 4 つのタブがあり、各タブは異なるアクティビティを実行します。プログラムのメインアクティビティにタブを合わせ、最初のタブが画面のデフォルトになります。最初のタブはリストビューでアナウンスを表示します。このアプリは Android 3.0 以降で動作しますが、2.3.3 では動作しません。タブを追加すると、メインアクティビティで強制的に閉じられます。

    TabHost tabHost = getTabHost();     
    Log.w("mainactivity", "200 ");

    TabSpec tabspec1 = tabHost.newTabSpec("Duyurular");
    Log.w("mainactivity", "201 ");
    tabspec1.setIndicator("Duyuru");
    Log.w("mainactivity", "202 ");
    Intent tab1Intent = new Intent(this, duyurular.class);
    Log.w("mainactivity", "203 ");
    tabspec1.setContent(tab1Intent);
    Log.w("mainactivity", "204 ");
    tabHost.addTab(tabspec1); 
    Log.w("mainactivity", "205 ");

LogCat で mainactivty 204 が表示されますが、205 は表示されません。

MainActivty.java

public class MainActivity extends TabActivity {
static final int DIALOG_ERROR_CONNECTION = 1;
static final int YANLIS_VERI_GIRISI = 2;
static final int CIKIS_YAP = 3;
static final int ILETISIM = 4;
static final int Zorunlu_Kapat=5;
static String responseBody = null;
static String  rehberResponse=null;
static String  birimlerResponse=null;
static String   yemekresponseBody=null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (isOnline(getApplicationContext())==true) 
    {

        Log.w("mainactivity", "100 ");
        TablariAyarla();

        final TabHost tabHost = getTabHost();   
        setTabColor(tabHost);       // ilk sayfa gelince tab renkleri

        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {   //tıklanınca tab renklerinin ayarlanması. 
                // TODO Auto-generated method stub
                int tab = tabHost.getCurrentTab();
                setTabColor(tabHost);
            }
        });

    }
    }   

public static void setTabColor(TabHost tabhost) {       //seçili  tab arka plan rengi ayarı
    for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
    {
        Log.w("mainactivity", "300 ");
      //  tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#B3A9A9")); //unselected
        tabhost.getTabWidget().setBackgroundResource(R.drawable.bttn_blue);
        TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
        tv.setTextColor(Color.BLACK);
        tv.setTextSize(8);
    }
    Log.w("mainactivity", "400 ");
 //   tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#ee4000")); // selected
    tabhost.getTabWidget().setBackgroundResource(R.drawable.bttn_blue);
    TextView tv = (TextView) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).findViewById(android.R.id.title);
    tv.setTextColor(Color.WHITE);
    tv.setTextSize(8);   //tab başlığının boyutu

}

public void TablariAyarla () {   //Kaç tab olması isteniyorsa burda ve manifest dosyasında okdar tanımlanmalı.
    TabHost tabHost = getTabHost();     
    Log.w("mainactivity", "200 ");

    TabSpec tabspec1 = tabHost.newTabSpec("Duyurular");
    Log.w("mainactivity", "201 ");
    tabspec1.setIndicator("Duyuru");
    Log.w("mainactivity", "202 ");
    Intent tab1Intent = new Intent(this, duyurular.class);
    Log.w("mainactivity", "203 ");
    tabspec1.setContent(tab1Intent);
    Log.w("mainactivity", "204 ");

    TabSpec tabspec2 = tabHost.newTabSpec("Yemek Listesi");
    tabspec2.setIndicator("Yemekhane");
    Intent tab2Intent = new Intent(this, yemekListesi.class);
    tabspec2.setContent(tab2Intent);


    TabSpec tabspec3 = tabHost.newTabSpec("Konumunuz");
    tabspec3.setIndicator("Konum");
    Intent tab3Intent = new Intent(this, konumunuz.class);
    tabspec3.setContent(tab3Intent);

    TabSpec tabspec4 = tabHost.newTabSpec("Dahililer");
    tabspec4.setIndicator("Rehber");
    Intent tab4Intent = new Intent(this, telefon_rehberi.class);
    tabspec4.setContent(tab4Intent);
    Log.w("mainactivity", "404");
    // Adding all TabSpec to TabHost
    tabHost.addTab(tabspec1); 
    tabHost.addTab(tabspec2); 
    tabHost.addTab(tabspec3); 
    tabHost.addTab(tabspec4); 
    Log.w("mainactivity", "500 ");
}

** duyurular.java (最初のタブの Java) **

public class duyurular extends Activity {
static final int DIALOG_ERROR_CONNECTION = 1;
static final int YANLIS_VERI_GIRISI = 2;
static final int CIKIS_YAP = 3;
static final int ILETISIM = 4;
static JSONObject tmp;
static JSONArray jArrayDuyurular;
static String responseBody,rehberResponse,birimlerResponse = null;
static ArrayList<String>deneme = null;
static ArrayList<DuyurularSinifi> duyuruArray = new ArrayList<DuyurularSinifi>();
static View row=null;
int save = -1;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.duyurular);
    Log.w("duyurular.java", "girdiiii222");
     final ListView listwiev1 = (ListView) findViewById(R.id.listView1);

    new Thread(new Runnable() { 
    public void run() {

            try {
                Log.w("duyurular.java", "girdiiii");
//  2.3 için kaldırıdldı
        //       ColorDrawable divcolor = new ColorDrawable(R.color.DarkOrange1);    //itemlar arası ayırıcı çizgi
        //          listwiev1.setDivider(divcolor);
        //          listwiev1.setDividerHeight(2);                  
                 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                    Log.i("versiyona bakıldı","3.1 den küçük");
                 }else{
                            listwiev1.setBackgroundColor(R.color.ubsacikmavi);   
                    };
                    responseBody=Giris.responseBody;
                    rehberResponse=Giris.rehberResponse;
                    birimlerResponse=Giris.birimlerResponse;;

                        if (responseBody != "") { // Json alındı
                            Log.w("duyurular.java", "girdiiii");
                            jArrayDuyurular = new JSONArray(responseBody);
                        //  System.out.println(responseBody);
                            JSONBol();

                        } else {
                            hataver("Veri alınırken hata oluştu");
                        }
            } catch (Exception e) {
                Log.w("tab1", "250 ");
                e.printStackTrace();
                // TODO: handle exception
            }

        }
        }).start();

    listwiev1.setOnItemClickListener(new OnItemClickListener() {   //listview tıklanınca arka plan rengi ayarı
          public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {

            //  listwiev1.getChildAt(myItemInt).setBackgroundResource(R.color.green);
            // Log.w("deneme",( Long.toString(listwiev1.getSelectedItemId())));
            /*  if (listwiev1.getSelectedItemPosition() == -1 ){  //) || myItemInt == 1){
                  listwiev1.getChildAt(myItemInt).setBackgroundColor(getResources().getColor(R.color.tabmavisi));//  Color.parseColor("#CAA48A"));

              }*/

            //  String selectedFromList =listwiev1.getAdapter().getItem(myItemInt).toString();
              String url=duyuruArray.get(myItemInt).geturl();           //duyurularla ilgili url yi arraydan alma

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);       

          }
    }); 

}

**activty_main.xml* *

  <?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="false"
        android:dividerPadding="2dp"
        android:showDividers="middle" />

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

duyurular.xml (最初のタブ)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/tabmavisi"
    android:padding="5dp"
    android:text="Üniversite Duyuruları"
    android:textColor="#FFFFFF"
    android:textSize="18dp"
    android:textStyle="bold"
    android:typeface="normal" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/ubsacikmavi"
        android:divider="?android:attr/listDividerAlertDialog"
        android:dividerHeight="5dp" >

    </ListView>
</LinearLayout>

* product_row.xml (リストビューの行)*

  <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical" >

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/tabmavisi"
    android:padding="5dp"
    android:text="Üniversite Duyuruları"
    android:textColor="#FFFFFF"
    android:textSize="18dp"
    android:textStyle="bold"
    android:typeface="normal" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@color/ubsacikmavi"
        android:divider="?android:attr/listDividerAlertDialog"
        android:dividerHeight="5dp" >

    </ListView>
</LinearLayout>

これは私のlogcat出力

          08-28 07:21:25.173: E/AndroidRuntime(723): FATAL EXCEPTION: main
          08-28 07:21:25.173: E/AndroidRuntime(723): java.lang.RuntimeException: Unable to start       activity ComponentInfo{nevsehir.portal/portal.MainActivity}: java.lang.RuntimeException:  Unable to start activity ComponentInfo{nevsehir.portal/portal.duyurular}:  android.view.InflateException: Binary XML file line #23: Error inflating class  android.widget.ListView
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.os.Handler.dispatchMessage(Handler.java:99)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.os.Looper.loop(Looper.java:130)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.main(ActivityThread.java:3683)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at java.lang.reflect.Method.invokeNative(Native Method)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at java.lang.reflect.Method.invoke(Method.java:507)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at dalvik.system.NativeStart.main(Native Method)
          08-28 07:21:25.173: E/AndroidRuntime(723): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{nevsehir.portal/portal.duyurular}: android.view.InflateException: Binary XML file line #23: Error inflating class android.widget.ListView
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1487)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.widget.TabHost.setCurrentTab(TabHost.java:326)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.widget.TabHost.addTab(TabHost.java:216)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at portal.MainActivity.TablariAyarla(MainActivity.java:136)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at portal.MainActivity.onCreate(MainActivity.java:69)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
          08-28 07:21:25.173: E/AndroidRuntime(723):    ... 11 more
          08-28 07:21:25.173: E/AndroidRuntime(723): Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class android.widget.ListView
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.Activity.setContentView(Activity.java:1657)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at portal.duyurular.onCreate(duyurular.java:67)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
          08-28 07:21:25.173: E/AndroidRuntime(723):    ... 21 more
          08-28 07:21:25.173: E/AndroidRuntime(723): Caused by: java.lang.reflect.InvocationTargetException
          08-28 07:21:25.173: E/AndroidRuntime(723):    at java.lang.reflect.Constructor.constructNative(Native Method)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
          08-28 07:21:25.173: E/AndroidRuntime(723):    ... 33 more
          08-28 07:21:25.173: E/AndroidRuntime(723): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x1010305 a=-1}
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.content.res.Resources.loadDrawable(Resources.java:1681)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.widget.ListView.<init>(ListView.java:175)
          08-28 07:21:25.173: E/AndroidRuntime(723):    at android.widget.ListView.<init>(ListView.java:159)
          08-28 07:21:25.173: E/AndroidRuntime(723):    ... 36 more
4

1 に答える 1

0

リスト行を見てください:

Resources$NotFoundException: リソースは Drawable (色またはパス) ではありません: TypedValue{t=0x2/d=0x1010305 a=-1}

定義"@color/ubsacikmaviはドローアブルである必要がありますが、ドローアブルではないようです (のドキュメントを参照android:background)

于 2013-08-28T07:56:24.337 に答える