Why am I getting the error : android.content.res.Resources$Notfoundexception: Resource ID #0x0

Asked

Viewed 374 times

0

Can anyone explain to me what the mistake is in this code? I honestly don’t understand why I’m getting this mistake !

Java :

public class Chose_curso extends AppCompatActivity {

    private TextView pickLetraText;
    private ListView cursoList;
    private Spinner letraPicker;

    private ArrayList<String> letras = new ArrayList<String>();
    private ArrayList<String> cursos = new ArrayList<String>();


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


        pickLetraText = (TextView) findViewById(R.id.pickLetraText);
        cursoList = (ListView) findViewById(R.id.cursoList);
        letraPicker = (Spinner) findViewById(R.id.letraPicker);

        letras.add("A");
        letras.add("B");
        letras.add("C");
        letras.add("D");
        letras.add("E");
        letras.add("F");
        letras.add("G");
        letras.add("H");
        letras.add("I");
        letras.add("J");
        letras.add("L");
        letras.add("M");
        letras.add("N");
        letras.add("O");
        letras.add("P");
        letras.add("Q");
        letras.add("R");
        letras.add("S");
        letras.add("T");
        letras.add("U");
        letras.add("V");


        ArrayAdapter<String> adapterLetras = new ArrayAdapter<String>(Chose_curso.this,0,letras);

        adapterLetras.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        letraPicker.setAdapter(
                new NothingSelectedSpinnerAdapter(
                        adapterLetras,
                        R.layout.contact_spinner_row_nothing_selected,
                        // R.layout.contact_spinner_nothing_selected_dropdown, // Optional
                        this));

        Document document = null;


        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                try  {
                    if(letraPicker.getSelectedItem()!=null){
                    Document document = null;

                    document = Jsoup.connect("http://www.dges.gov.pt/guias/indcurso.asp?letra="+letraPicker.getSelectedItem().toString()).get();

                    for(int contador=0;contador<document.select(".lin-area-c2").size();contador++){
                        cursos.add(document.select(".lin-area-c2").get(contador).text());}}

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();

        ArrayAdapter<String> cursosAdapter = new ArrayAdapter<String>(Chose_curso.this,0,cursos);

        cursoList.setAdapter(cursosAdapter);
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pedrogouveia.averagemaker.Chose_curso"
android:background="@color/Cyan">

<TextView
    android:id="@+id/pickLetraText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="25dp"
    android:layout_marginTop="39dp"
    android:text="Escolha a letra inicial do seu curso :"
    android:textColor="@color/white"
    android:textSize="@dimen/_14sdp"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true" />

<Spinner
    android:id="@+id/letraPicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/pickLetraText"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="17dp"
    android:layout_alignTop="@+id/pickLetraText"
    android:scaleX="0.75"
    android:scaleY="0.75"/>

<ListView
    android:id="@+id/cursoList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/pickLetraText"
    android:layout_marginTop="54dp" />

Error:

 FATAL EXCEPTION: main
                                             Process: com.pedrogouveia.averagemaker, PID: 4397
                                             android.content.res.Resources$NotFoundException: Resource ID #0x0
                                                 at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:194)
                                                 at android.content.res.Resources.loadXmlResourceParser(Resources.java:2131)
                                                 at android.content.res.Resources.getLayout(Resources.java:1142)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:424)
                                                 at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:416)
                                                 at android.widget.ArrayAdapter.getView(ArrayAdapter.java:407)
                                                 at com.pedrogouveia.averagemaker.NothingSelectedSpinnerAdapter.getView(NothingSelectedSpinnerAdapter.java:66)
                                                 at android.widget.Spinner.measureContentWidth(Spinner.java:856)
                                                 at android.widget.Spinner.onMeasure(Spinner.java:606)
                                                 at android.support.v7.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:416)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                                                 at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6549)
                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                 at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6549)
                                                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                                                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                                                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6549)
                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6549)
                                                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
                                                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
                                                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6549)
                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                 at com.android.internal.policy.DecorView.onMeasure(DecorView.java:699)
                                                 at android.view.View.measure(View.java:21783)
                                                 at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2409)
                                                 at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1497)
                                                 at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1750)
                                                 at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1385)
                                                 at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6722)
                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:886)
                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:698)
                                                 at android.view.Choreographer.doFrame(Choreographer.java:633)
                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:872)
                                                 at android.os.Handler.handleCallback(Handler.java:769)
                                                 at android.os.Handler.dispatchMessage(Handler.java:98)
                                                 at android.os.Looper.loop(Looper.java:164)
                                                 at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  • You could ease by telling which line of code this error happens.

  • The only problem is that it doesn’t say in logcat ! I will post the logcat.

  • Try changing your arraydatpter to: ArrayAdapter<String> adapterLetras = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,letras);

2 answers

2


Instead of leaving the second parameter as 0 in his ArrayAdapter, pass the android.R.layout.simple_spinner_item as layout item. See how it should look:

ArrayAdapter<String> adapterLetras = new ArrayAdapter<String>(
                this, android.R.layout.simple_spinner_item, letras);
adapterLetras.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

0

Try to update this:

 cursos.add(document.select(".lin-area-c2").get(contador).text());}}

For this:

 cursos.add(String.valueOf((document.select(".lin-area-c2").get(contador).text()));}}
  • I tried and did not give :/ continues to give the same error

Browser other questions tagged

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