Resources$Notfoundexception: Resource ID #0x7f060007 type #0x12 is not Valid

Asked

Viewed 230 times

2

When finished creating a listFragment and calling it in main the apk terminates giving the error below: erro

Here is my Listfragment:

    ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
SimpleAdapter adapter;
String[] atividades = new String[]{"item1", "item2", "item3"};
int[] imageId = {
        R.drawable.imagem1,
        R.drawable.image2,
        R.drawable.image3,
  };

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    HashMap<String, String> map = new HashMap<String, String>();
    for (int i = 0; i < atividades.length; i++) {
        map = new HashMap<String, String>();
        map.put("atividade", atividades[i]);
        map.put("imagem", Integer.toString(imageId[i]));
        data.add(map);
    }
    String[] from = {"atividade", "imageId"};
    int[] to = {R.id.txt, R.id.img};
    adapter = new SimpleAdapter(getActivity(), data, R.id.listView, from, to);
    setListAdapter(adapter);
    return super.onCreateView(inflater, container, savedInstanceState);
}

and my main class:

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    FirstFragment fragment = new FirstFragment();
    android.support.v4.app.FragmentTransaction fragmentTransaction =
            getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, fragment);
    fragmentTransaction.commit();

1 answer

3


In the SimpleAdapter , must pass a layout, not a id:

adapter = new SimpleAdapter(getActivity(), data, R.id.listView, from, to);

To correct:

adapter = new SimpleAdapter(getActivity(), data, R.layout.layout_da_lista, from, to);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.