Skip to content Skip to sidebar Skip to footer

Type Mismatch: Cannot Convert From String To R.string

I am new so forgive my primitive question, I am really not getting this. I am simply creating this array on my main activity while doing a tutorial and I get an error package com.T

Solution 1:

Easy fix, the String type needs to be capitalized.

string[] items = newstring[]{"aa","bb"};
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,R.layout.reminder_row,R.id.text1,items);

Becomes:

String[] items = newString[]{"aa","bb"};
ArrayAdapter<String> adapter = newArrayAdapter<String>(this,R.layout.reminder_row,R.id.text1,items);

@gt_ebuddy is right as well, remove this line:

import android.R.string;

Using Ctrl+Shift+O is the simplest way to import classes automatically, but it sometimes leads you astray when it tries to import anything from your package's R file.

Solution 2:

Remove the import. and be happy.

import android.R.string;

And note that

  • It should be String. Not string
  • String class is defined in package java.lang and you will never require to import this package because they are automatically imported into every java program. Java Doc says "Package java.lang : Provides classes that are fundamental to the design of the Java programming language."

Solution 3:

Remove the import android.R.string;. I guess you have done that because of error shown on that line string should be in your R.java file it is automatically generated do not modify it Clean your project and build again Hope it works !!!!

Solution 4:

string[] items = newstring[]{"aa","bb"};
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,R.layout.reminder_row,R.id.text1,items);

change this to

String[] items = newString[]{"aa","bb"};
ArrayAdapter<String> adapter = newArrayAdapter<String>(this,R.layout.reminder_row,R.id.text1,items)

Post a Comment for "Type Mismatch: Cannot Convert From String To R.string"