[SOLVED] Lists.newArrayList() Cannot be Resolved?

Put your problem here if it does not fit any of the other categories.

[SOLVED] Lists.newArrayList() Cannot be Resolved?

Postby Raskolnikov » Tue May 25, 2010 1:54 am

I am trying to add some functionality to a test app i have to be able to add a contact to the ContactProvider.

I have the project set to Android 2.0 and am trying to utilize a batch insert as reccomended by the Android Dev Docs.

Here is my .java file:

Code: Select all
package com.test.AddContactTest20;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ContentProviderOperation;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.RawContacts;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;



public class AddContactTest20 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
      //Button Action
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {   
           public void onClick(View v) {       
              // Perform action on clicks       
              
                ArrayList<ContentProviderOperation> ops = Lists.newArrayList();
                int rawContactInsertIndex = ops.size();
                ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)         
                      .withValue(RawContacts.ACCOUNT_TYPE, "TEXT")         
                      .withValue(RawContacts.ACCOUNT_NAME, "2.0 Account Name")         
                      .build()); ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)         
                            .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)         
                            .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)         
                            .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")         
                            .build());
               
                getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
               
               
                Toast.makeText(AddContactTest20.this,ops.toString(),Toast.LENGTH_SHORT).show();
           }
        });
    }
}


For some reason I get an error saying "Lists cannot be resolved", pointing to the reference about halfway down the code (Line 32). Am i missing an import? Do i have something set up incorrectly here. I have browsed Goog for the past hour or so and it looks as though no one has had this issue, so i figure i have something setup wrong.

Any help would be appreciated.

Thanks
Ras
Last edited by Raskolnikov on Wed Jun 02, 2010 4:30 pm, edited 1 time in total.
Raskolnikov
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue May 18, 2010 4:54 am

Top

Re: Lists.newArrayList() Cannot be Resolved?

Postby nicholas.hauschild » Tue May 25, 2010 5:35 am

A stack trace would be helpful :)
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: Lists.newArrayList() Cannot be Resolved?

Postby Raskolnikov » Tue May 25, 2010 12:46 pm

hmmm.....

Now i feel kind of useless here. I can find the console log, that has no relavent data and only is added to when I run the app. I see in the debugging area a window called LogCat, but again it only gives me info when i run the app and currently has no relavent data.

I thought maybe i could get more info If I ran the app, but Eclipse wont let me as it says i have an unfixed error.

To be honest, I am not sure where to look for the stack trace. I have just moved to Java/Eclipse within the last week or so from a C#.net environment.

Maybe a little assistance in locating the stack trace as that would be extremely helpful in general.

I am using Eclipse Galileo to edit and run this app. I will be happy to post it once i find it.

Sorry for the elementary question here.
Ras
Raskolnikov
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue May 18, 2010 4:54 am

Re: Lists.newArrayList() Cannot be Resolved?

Postby nicholas.hauschild » Tue May 25, 2010 1:10 pm

No worries, everyone needs to start somewhere, right?

LogCat is going to be where you want to look for your stack trace, and you should be able to log your own things to LogCat with the android.util.Log class. LogCat will be useful once you can get your app running again.

As for your unfixed error, you should be able to identify it within the 'problems' tab in eclipse.

Good Luck
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: Lists.newArrayList() Cannot be Resolved?

Postby Raskolnikov » Tue May 25, 2010 1:16 pm

gottcha.

OK, so the "error" that is preventing me from running the app IS the "Lists cannot be resolved error" so unless i am missing something that would tell me more information about it, I cant run the app to let the logcat catch the exception thrown.

any ideas?
Ras
Raskolnikov
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue May 18, 2010 4:54 am

Re: Lists.newArrayList() Cannot be Resolved?

Postby nicholas.hauschild » Tue May 25, 2010 1:33 pm

Well, I am no .Net guru, but perhaps this is the issue:

ArrayList<ContentProviderOperation> ops = Lists.newArrayList();

For this to work, you need to have a Class named Lists with a static method newArrayList(); which would return a new ArrayList implementation.

I am assuming this might be some .Net syntax, and you actually want to simply create a new instance of an ArrayList.

You should do that like this (at least in this case):

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

Hope this helps!
-Nick
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Top

Re: Lists.newArrayList() Cannot be Resolved?

Postby Raskolnikov » Tue May 25, 2010 1:59 pm

hmm.....Well, this shouldnt have anything to do with .net. I say that because i basically copy and pasted this code from the google dev website. This is the exact code that i was referencing:

Code: Select all
ArrayList<ContentProviderOperation> ops = Lists.newArrayList();
    int rawContactInsertIndex = ops.size();
   
    ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)         
         .withValue(RawContacts.ACCOUNT_TYPE, accountType)         
         .withValue(RawContacts.ACCOUNT_NAME, accountName)         
         .build());

    ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)         
         .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)         
         .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)         
         .withValue(StructuredName.DISPLAY_NAME, "Mike Sullivan")         
         .build());

getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);



I copied the code directly from here: http://developer.android.com/reference/android/provider/ContactsContract.RawContacts.html

you'll notice the first line is the line i am having trouble with.

Ok...with that said I tried your suggestion: ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

That seems to work. I had tried it previously, but had not put the () at the end and so was still getting the error.....and so did not revisit it until you posted it.

I appreciate the help.
Raskolnikov
Junior Developer
Junior Developer
 
Posts: 11
Joined: Tue May 18, 2010 4:54 am

Re: Lists.newArrayList() Cannot be Resolved?

Postby nicholas.hauschild » Tue May 25, 2010 2:29 pm

I imagine the code you copied it from probably had a class/method declared which would've worked. Please let us know if you run into any more issues!
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: [SOLVED] Lists.newArrayList() Cannot be Resolved?

Postby Quelle » Wed Sep 08, 2010 1:39 pm

Same Problem, Eclipse can`t resolve Lists. It`s a example from the android developer site.
Quelle
Developer
Developer
 
Posts: 34
Joined: Thu Mar 11, 2010 10:53 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 13 guests