1

Android アプリケーションに問題があります。

サポート ライブラリ v7 を使用しています。ライブラリを Eclipse のプロジェクトとしてインポートし、プロジェクトでライブラリを構成しました。ActionBarActivity の FragmentActivity を変更しましたが、Android 2.3 Emulator を使用してアプリケーションを起動すると、互換性のある Emulator が見つからないというメッセージが表示されます。マニフェストには最小 SDK 8 (Froyo 2.2) がありますが、方法がありません。

アプリを起動すると、すぐにクラッシュします。これは私が得たログです:

11-13 21:11:37.637: E/AndroidRuntime(392): FATAL EXCEPTION: main
11-13 21:11:37.637: E/AndroidRuntime(392): android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
11-13 21:11:37.637: E/AndroidRuntime(392):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.AbsListView.obtainView(AbsListView.java:1430)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.ListView.makeAndAddView(ListView.java:1745)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.ListView.fillDown(ListView.java:670)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.ListView.fillFromTop(ListView.java:727)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.ListView.layoutChildren(ListView.java:1584)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.AbsListView.onLayout(AbsListView.java:1260)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.layout(View.java:7175)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:714)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.layout(View.java:7175)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.layout(View.java:7175)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.layout(View.java:7175)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.layout(View.java:7175)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.layout(View.java:7175)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.os.Looper.loop(Looper.java:130)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.app.ActivityThread.main(ActivityThread.java:3683)
11-13 21:11:37.637: E/AndroidRuntime(392):  at java.lang.reflect.Method.invokeNative(Native Method)
11-13 21:11:37.637: E/AndroidRuntime(392):  at java.lang.reflect.Method.invoke(Method.java:507)
11-13 21:11:37.637: E/AndroidRuntime(392):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-13 21:11:37.637: E/AndroidRuntime(392):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-13 21:11:37.637: E/AndroidRuntime(392):  at dalvik.system.NativeStart.main(Native Method)
11-13 21:11:37.637: E/AndroidRuntime(392): Caused by: java.lang.reflect.InvocationTargetException
11-13 21:11:37.637: E/AndroidRuntime(392):  at java.lang.reflect.Constructor.constructNative(Native Method)
11-13 21:11:37.637: E/AndroidRuntime(392):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
11-13 21:11:37.637: E/AndroidRuntime(392):  ... 35 more
11-13 21:11:37.637: E/AndroidRuntime(392): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x10102fd a=-1}
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.content.res.Resources.loadDrawable(Resources.java:1681)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.view.View.<init>(View.java:1951)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.TextView.<init>(TextView.java:350)
11-13 21:11:37.637: E/AndroidRuntime(392):  at android.widget.TextView.<init>(TextView.java:343)
11-13 21:11:37.637: E/AndroidRuntime(392):  ... 38 more

これは activity_main レイアウト コードです。

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp" >
        </android.support.v4.view.ViewPager>
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#fca402"/>
</android.support.v4.widget.DrawerLayout>

MainActivity クラスのコードは次のとおりです。

 import android.support.v4.app.ActionBarDrawerToggle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentTransaction;
    import android.support.v4.view.GravityCompat;
    import android.support.v4.view.ViewPager;
    import android.support.v4.widget.DrawerLayout;
    import android.support.v7.app.ActionBar;
    import android.support.v7.app.ActionBar.Tab;
    import android.support.v7.app.ActionBarActivity;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.ViewGroup;

    public class MainActivity extends ActionBarActivity implements
    ActionBar.TabListener {
        private MenuItem menuItem;
        private ViewPager viewPager;
        private TabsPagerAdapter mAdapter;
        public ActionBar actionBar;
        private DrawerLayout mDrawerLayout;
        private ListView mDrawerList;
        private ActionBarDrawerToggle mDrawerToggle;
        private String[] mPlanetTitles;

         public static String usuarioID;
            public static String usuarioname;
            public static String claveusuario;
            public static String registrationID;

            ConnectionDetector cd;
            static Httppostaux post;
            static TextView textView;
            public static SessionManager session;

            JSONObject jsonobject;
            JSONObject jsonobject1;
            JSONArray jsonarray;
            ListView listview;
            ListViewAdapter adapter;
            ProgressDialog mProgressDialog;
            ArrayList<HashMap<String, String>> arraylist;
            AsyncTask<Void, Void, Void> mRegisterTask;
            static String IMAGEN = "imagen";
            static String QUIEN = "quien";
            static String REPORTE = "reporte";
            static String FECHA = "fecha";
            static String IMGS = "imgs";
            static String VIDEO = "video";
            static String CONTENIDOPOST = "contenidopost";
            Runnable Refresh;
            ImageButton refresh;
            ImageButton postear;
            int current_page = 1;
            boolean loadingMore = false;
        // Tab titles
        private String[] tabs = { "Reportes", "Cámaras", "Video en vivo" };

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            actionBar = getSupportActionBar();
            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);

            // Initilization
            viewPager = (ViewPager) findViewById(R.id.pager);
            mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

            viewPager.setAdapter(mAdapter);
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        

            // Adding Tabs
            for (String tab_name : tabs) {
                actionBar.addTab(actionBar.newTab().setText(tab_name)
                        .setTabListener(this));
            }

            /**
             * on swiping the viewpager make respective tab selected
             * */
            viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

                @Override
                public void onPageSelected(int position) {
                    // on changing the page
                    // make respected tab selected
                    actionBar.setSelectedNavigationItem(position);
                }

                @Override
                public void onPageScrolled(int arg0, float arg1, int arg2) {
                }

                @Override
                public void onPageScrollStateChanged(int arg0) {
                }
            });

    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
            mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
            mDrawerList = (ListView) findViewById(R.id.left_drawer);

         // set a custom shadow that overlays the main content when the drawer opens
            mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
            // set up the drawer's list view with items and click listener
            mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                    R.layout.drawer_list_item, mPlanetTitles));
            mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

            // enable ActionBar app icon to behave as action to toggle nav drawer
           getSupportActionBar().setDisplayHomeAsUpEnabled(true);
           getSupportActionBar().setHomeButtonEnabled(true);

            // ActionBarDrawerToggle ties together the the proper interactions
            // between the sliding drawer and the action bar app icon
            mDrawerToggle = new ActionBarDrawerToggle(
                    this,                  /* host Activity */
                    mDrawerLayout,         /* DrawerLayout object */
                    R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
                    R.string.drawer_open,  /* "open drawer" description for accessibility */
                    R.string.drawer_close  /* "close drawer" description for accessibility */
                    ) {
                public void onDrawerClosed(View view) {
                    //getActionBar().setTitle(mTitle);
                    supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                }

                public void onDrawerOpened(View drawerView) {
                    //getActionBar().setTitle(mDrawerTitle);
                    supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                }
            };
            mDrawerLayout.setDrawerListener(mDrawerToggle);

            if (savedInstanceState == null) {
                selectItem(0);
            }
       }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // on tab selected
            // show respected fragment view
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
          }

        @Override
          public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_load:
              menuItem = item;
             // menuItem.setActionView(R.layout.progressbar);
              //menuItem.expandActionView();
              new DownloadJSON().execute();
              break;
            case R.id.menu_reporte:
                  menuItem = item;
                  //menuItem.expandActionView();
                  Intent i=new Intent(getApplicationContext(),ReporteActivity.class);
                    i.putExtra("userId", usuarioID);
                    startActivity(i);
                  break;
            default:
              break;
            }
            return true;
          }

@Override
    public void onBackPressed() {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);
    } 
    /* The click listner for ListView in the navigation drawer */
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    }

    private void selectItem(int position) {
        // update the main content by replacing fragments
        Fragment fragment = new PlanetFragment();
        Bundle args = new Bundle();
        args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
        fragment.setArguments(args);

        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.pager, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        setTitle(mPlanetTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    }

    @Override
    public void setTitle(CharSequence title) {
        //mTitle = title;
        //getActionBar().setTitle(mTitle);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    /**
     * Fragment that appears in the "content_frame", shows a planet
     */
    public static class PlanetFragment extends Fragment {
        public static final String ARG_PLANET_NUMBER = "planet_number";

        public PlanetFragment() {
            // Empty constructor required for fragment subclasses
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_planet, container, false);
            int i = getArguments().getInt(ARG_PLANET_NUMBER);
            String secciones = getResources().getStringArray(R.array.planets_array)[i];

            if (i == 2){
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage("¿Estás seguro de cerrar sesión en VideoTráfico.com?.")
                       .setCancelable(false)
                       .setPositiveButton("Si, estoy seguro", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                               new asynclogout().execute(usuarioID);
                           }
                       })
                       .setNegativeButton("No gracias", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                           }
                       });
                AlertDialog alert = builder.create();
                alert.show();
            }
            if (i == 1){
                Intent intent=new Intent(getActivity().getApplication(),PrefsActivity.class);
                startActivity(intent);
            }
            if (i == 0){

            }
            //int imageId = getResources().getIdentifier(secciones.toLowerCase(Locale.getDefault()),
                            //"drawable", getActivity().getPackageName());
           // ((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId);
           // getActivity().setTitle(secciones);
            return rootView;
        }
}
4

1 に答える 1