Android.content.res.Resources $ NotFoundException: String-Array-Ressourcen-ID # 0x7f070002

Ich habe Probleme, ein String-Array für strings.xml zu bekommen.

Der Fehler ist:

android.content.res.Resources$NotFoundException: String array resource ID #0x7f070002 at android.content.res.Resources.getStringArray(Resources.java:472) at com.klh.lehava.MainActivity.onCreate(MainActivity.java:87) 

Im Grunde, was ich versuche zu tun ist, um ein String-Array namens planets_array , und speichern Sie es in mPlanetTitles . Dies ist eines der Google-Beispiele für Navigations-Schublade, und ich habe es von ihrer Website heruntergeladen und geändert.

Aus irgendeinem Grund bekomme ich diesen Fehler nicht auf Nexus 4 (Android 5.0 Lollipop), aber ich bekomme das Problem auf Galaxy S3 und LG G2 (Android 4.4.4)

Hier ist mein vollständiger Code:

 public class MainActivity extends Activity { private static MainActivity instance; public MainActivity() { instance = this; } private static String response_str; private static HttpResponse result; private DrawerLayout mDrawerLayout; private static ListView mDrawerList; private ActionBarDrawerToggle mDrawerToggle; private ArrayAdapter<String> adapter1; private static String isUserLoggedIn; private static String getUrl; public String getUrl() { return getUrl; } public static final String TAG = "loginCookie"; private CharSequence mDrawerTitle; private static CharSequence mTitle; //private final ArrayList<String> assignArr0 = new ArrayList<String>(); private static String[] mPlanetTitles; private static String[] mPlanetTitlesDisconnected; private static String[] mPlanetTitlesConnected; private static int checked; private String[] newAr; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView webview; webview = (WebView) findViewById(R.id.webview); mTitle = mDrawerTitle = getTitle(); mPlanetTitles = getResources().getStringArray(R.array.planets_array); mPlanetTitlesDisconnected = getResources().getStringArray(R.array.mPlanetTitlesDisconnected); mPlanetTitlesConnected = getResources().getStringArray(R.array.mPlanetTitlesConnected); 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 adapter1 = new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitlesDisconnected); mDrawerList.setAdapter(adapter1); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } // Handle action buttons switch (item.getItemId()) { default: return super.onOptionsItemSelected(item); } } 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 Bundle args = new Bundle(); //isUserLoggedIn=IsLoggedIn(); if (isUserLoggedIn == null) { Fragment fragment = new MainFragment(); args.putInt(MainFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } else { if (isUserLoggedIn.equals("0")) { if (position == 0) { Fragment fragment = new MainFragment(); args.putInt(MainFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } if (position == 1) { Fragment fragment = new AboutFragment(); args.putInt(AboutFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } } else if (isUserLoggedIn.equals("1")) { if (position == 0) { Fragment fragment = new InOutFragment(); args.putInt(InOutFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } if (position == 1) { Fragment fragment = new AddEventFragment(); args.putInt(AddEventFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } if (position == 2) { Fragment fragment = new AboutFragment(); args.putInt(AboutFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(position, true); setTitle(mPlanetTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); } if (position == 3) { Fragment fragment = new WebLogoutFragment(); args.putInt(WebLogoutFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(args); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); mDrawerList.setItemChecked(0, true); setTitle(mPlanetTitles[0]); mDrawerLayout.closeDrawer(mDrawerList); } } } // update selected item and title, then close the drawer } @Override public void setTitle(CharSequence title) { mTitle = title; getActionBar().setTitle(mTitle); } @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); } 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 planet = getResources().getStringArray(R.array.planets_array)[i]; int imageId = getResources().getIdentifier(planet.toLowerCase(Locale.getDefault()), "drawable", getActivity().getPackageName()); ((ImageView) rootView.findViewById(R.id.image)).setImageResource(imageId); getActivity().setTitle(planet);*/ return null; } } public static class AboutFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public AboutFragment() { // Empty constructor required for fragment subclasses } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_about, container, false); int i = getArguments().getInt(ARG_PLANET_NUMBER); String planet = getResources().getStringArray(R.array.planets_array)[i]; getActivity().setTitle(planet); return rootView; } } public static class MainFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public static final String MY_DOMAIN = "klh-dev.com"; public MainFragment() { // Empty constructor required for fragment subclasses } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_web, container, false); int i = getArguments().getInt(ARG_PLANET_NUMBER); String planet = getResources().getStringArray(R.array.planets_array)[i]; WebView webview; webview = (WebView) rootView.findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { String weburl = view.getUrl(); String cookies = CookieManager.getInstance().getCookie(url); getUrl = view.getUrl(); isUserLoggedIn = IsLoggedIn(); Log.d(TAG, "All the cookies in a string:" + cookies); if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mlogin.php")) { mDrawerList.setItemChecked(0, true); getActivity().getActionBar().setTitle("התחברות"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mtimecounter.php")) { mDrawerList.setItemChecked(1, true); getActivity().getActionBar().setTitle("כניסה/יציאה"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/madd.php")) { mDrawerList.setItemChecked(2, true); getActivity().getActionBar().setTitle("הוספת אירוע"); } } }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setUseWideViewPort(true); webview.setWebChromeClient(new WebChromeClient()); webview.loadUrl("http://www.klh-dev.com/lehava/lehava/system/mlogin.php"); getActivity().setTitle(planet); return rootView; } } public static class InOutFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public static final String MY_DOMAIN = "klh-dev.com"; public InOutFragment() { // Empty constructor required for fragment subclasses } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_web, container, false); int i = getArguments().getInt(ARG_PLANET_NUMBER); String planet = getResources().getStringArray(R.array.planets_array)[i]; WebView webview; webview = (WebView) rootView.findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { String weburl = view.getUrl(); String cookies = CookieManager.getInstance().getCookie(url); getUrl = view.getUrl(); isUserLoggedIn = IsLoggedIn(); Log.d(TAG, "All the cookies in a string:" + cookies); if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mlogin.php")) { mDrawerList.setItemChecked(0, true); getActivity().getActionBar().setTitle("התחברות"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mtimecounter.php")) { mDrawerList.setItemChecked(1, true); getActivity().getActionBar().setTitle("כניסה/יציאה"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/madd.php")) { mDrawerList.setItemChecked(2, true); getActivity().getActionBar().setTitle("הוספת אירוע"); } } }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setUseWideViewPort(true); webview.setWebChromeClient(new WebChromeClient()); webview.loadUrl("http://www.klh-dev.com/lehava/lehava/system/mtimecounter.php"); getActivity().setTitle(planet); return rootView; } } public static class AddEventFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public static final String MY_DOMAIN = "klh-dev.com"; public AddEventFragment() { // Empty constructor required for fragment subclasses } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_web, container, false); int i = getArguments().getInt(ARG_PLANET_NUMBER); String planet = getResources().getStringArray(R.array.planets_array)[i]; WebView webview; webview = (WebView) rootView.findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { String weburl = view.getUrl(); String cookies = CookieManager.getInstance().getCookie(url); getUrl = view.getUrl(); isUserLoggedIn = IsLoggedIn(); Log.d(TAG, "All the cookies in a string:" + cookies); if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mlogin.php")) { mDrawerList.setItemChecked(0, true); getActivity().getActionBar().setTitle("התחברות"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mtimecounter.php")) { mDrawerList.setItemChecked(1, true); getActivity().getActionBar().setTitle("כניסה/יציאה"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/madd.php")) { mDrawerList.setItemChecked(2, true); getActivity().getActionBar().setTitle("הוספת אירוע"); } } }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setUseWideViewPort(true); webview.setWebChromeClient(new WebChromeClient()); webview.loadUrl("http://www.klh-dev.com/lehava/lehava/system/madd.php"); getActivity().setTitle(planet); return rootView; } } public static class WebLogoutFragment extends Fragment { public static final String ARG_PLANET_NUMBER = "planet_number"; public WebLogoutFragment() { // Empty constructor required for fragment subclasses } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_web, container, false); WebView webview; webview = (WebView) rootView.findViewById(R.id.webview); webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { String weburl = view.getUrl(); String cookies = CookieManager.getInstance().getCookie(url); getUrl = view.getUrl(); isUserLoggedIn = IsLoggedIn(); Log.d(TAG, "All the cookies in a string:" + cookies); if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mlogin.php")) { mDrawerList.setItemChecked(0, true); getActivity().getActionBar().setTitle("התחברות"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mlogin.php?log=1")) { mDrawerList.setItemChecked(0, true); getActivity().getActionBar().setTitle("התחברות"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mtimecounter.php")) { mDrawerList.setItemChecked(1, true); getActivity().getActionBar().setTitle("כניסה/יציאה"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/madd.php")) { mDrawerList.setItemChecked(2, true); getActivity().getActionBar().setTitle("הוספת אירוע"); } else if (weburl.equals("http://www.klh-dev.com/lehava/lehava/system/mlogin.php?log=1")) { mDrawerList.setItemChecked(2, true); getActivity().getActionBar().setTitle("התחברות"); } } }); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setUseWideViewPort(true); webview.setWebChromeClient(new WebChromeClient()); webview.loadUrl("http://www.klh-dev.com/lehava/lehava/system/mlogout.php"); return rootView; } } public static BasicCookieStore getCookieStore(String cookies, String domain) { String[] cookieValues = cookies.split(";"); BasicCookieStore cs = new BasicCookieStore(); BasicClientCookie cookie; for (int i = 0; i < cookieValues.length; i++) { String[] split = cookieValues[i].split("="); if (split.length == 2) cookie = new BasicClientCookie(split[0], split[1]); else cookie = new BasicClientCookie(split[0], null); cookie.setDomain(domain); cs.addCookie(cookie); } return cs; } public void UpdateMenu() { runOnUiThread(new Runnable() { public void run() { if (isUserLoggedIn == null) { isUserLoggedIn = IsLoggedIn(); } int i; SparseBooleanArray localSparseBooleanArray; if (isUserLoggedIn.equals("0")) { mPlanetTitles = mPlanetTitlesDisconnected; } i = mDrawerList.getCount(); localSparseBooleanArray = mDrawerList.getCheckedItemPositions(); for (int j = 0; j < i ; j++) { if (isUserLoggedIn.equals("1")) { mPlanetTitles = mPlanetTitlesConnected; } mDrawerList.setAdapter(new ArrayAdapter(instance, R.layout.drawer_list_item, mPlanetTitles)); mDrawerList.setItemChecked(checked, true); if (localSparseBooleanArray.get(j)) { checked = j; } } } }); } public void showToast(final String toast) { runOnUiThread(new Runnable() { public void run() { Toast.makeText(instance, toast, Toast.LENGTH_SHORT).show(); } }); } public static String IsLoggedIn() { new Thread(new Runnable() { public void run() { BasicCookieStore localBasicCookieStore = getCookieStore(CookieManager.getInstance().getCookie(getUrl), "klh-dev.com"); BasicHttpContext localBasicHttpContext = new BasicHttpContext(); DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(); localDefaultHttpClient.setCookieStore(localBasicCookieStore); localBasicHttpContext.setAttribute("http.cookie-store", localBasicCookieStore); HttpGet localHttpGet = new HttpGet("http://klh-dev.com/lehava/lehava/system/isloggedin.php"); try { result = localDefaultHttpClient.execute(localHttpGet, localBasicHttpContext); response_str = EntityUtils.toString(result.getEntity()); System.out.println(response_str); instance.UpdateMenu(); isUserLoggedIn = response_str; } catch (ClientProtocolException localClientProtocolException) { localClientProtocolException.printStackTrace(); } catch (IOException localIOException) { localIOException.printStackTrace(); } } }).start(); String str = response_str; isUserLoggedIn = str; return str; } } 

Zeile 87:

 mPlanetTitles = getResources().getStringArray(R.array.planets_array); 

Strings.xml:

 <resources> <string name="app_name">Lehava</string> <string-array name="planets_array"> <item>login</item> <item>about</item> <item>start shift</item> <item>add event</item> <item>logout</item> </string-array> <string-array name="mPlanetTitlesDisconnected"> <item>login</item> <item>about</item> </string-array> <string-array name="mPlanetTitlesConnected"> <item>start shift</item> <item>add event</item> <item>about</item> <item>logout</item> </string-array> <string name="drawer_open">Open navigation drawer</string> <string name="drawer_close">Close navigation drawer</string> <string name="action_websearch">Web search</string> </resources> 

Ich habe versucht, eine Ressource namens res zu erstellen und verwenden Sie getResources () stattdessen und es hat nicht funktioniert. Das habe ich versucht

 Resources res = getResources(); mPlanetTitles = res.getStringArray(R.array.planets_array); 

  • Android ic_drawer.png Symbol in weißer Farbe?
  • Handling zurück drücken bei der Verwendung von Fragmenten in Android
  • Android: Import DrawerLayout kann nicht aufgelöst werden
  • Android Navigationsschublade Show Indikator für untere Ebene Fragmente
  • Mit Navigation Schublade in älteren Android
  • ActionBarDrawerToggle setzt keine Schubladenanzeige
  • Wie erstelle ich Mini-Schublade-Menü in Android?
  • Deaktivieren Sie das dunkle Fading in der Navigationsschublade
  • 2 Solutions collect form web for “Android.content.res.Resources $ NotFoundException: String-Array-Ressourcen-ID # 0x7f070002”

    Stellen Sie sicher, dass Sie keine Varianten der values Ressourcen haben, wobei das String-Array nur für eine Teilmenge der Varianten definiert ist. Beispielsweise:

     values-v21/strings.xml - defined values/strings.xml - not defined 

    Wenn die Ressource in mindestens einer Variante vorhanden ist, bekommt man den Eintrag in R und kann sich im Code verweisen, aber die Runtime-Ressourcendatei-Variante hat nicht unbedingt die Ressource.

    Ich habe diesen Fehler, weil ich TextView.setText(int) , um eine Zahl im Text zu setzen. Das Problem ist, dass Android denkt, dass die Ganzzahl eine ressource id ist. Deshalb sollte ich das Interger innerhalb von String.valueOf(int) einkapseln, damit der Code TextView.setText(String.valueOf(int));

    Das Android ist ein Google Android Fan-Website, Alles ├╝ber Android Phones, Android Wear, Android Dev und Android Spiele Apps und so weiter.