2

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.TaskReminder;

import android.R.string;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class ReminderListActivity extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reminder_list);
    string[] items = new string[]{"aa","bb"};
    ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,R.layout.reminder_row,R.id.text1,items);
    setListAdapter(adapter);


}

and the error on my string array is :

Multiple markers at this line - Line breakpoint:ReminderListActivity [line: 14] - onCreate(Bundle)

- Type mismatch: cannot convert from String to R.string

what's exactly happening here?

0

4 Answers 4

6

Easy fix, the String type needs to be capitalized.

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

Becomes:

String[] items = new String[]{"aa","bb"};
ArrayAdapter<String> adapter = new ArrayAdapter<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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks !! I can't describe how dumb I feel, my programming is getting rusty :P gotta dive in !!
4

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."

1 Comment

I gave you an upvote and combined our answers (with due credit), since I hadn't noticed the erroneous import line at first.
1

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 !!!!

Comments

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

change this to

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.