简体   繁体   中英

Cannot resolve FileUtils even if I've added compile method in dependencies

This is my problem. I got two error messages

  1. "Cannot reslove FileUtils'

  2. Grade DSL method not found: 'compile()'

  3. (+) The project may be using a version of Gradle that does not contain the method and The build may be missing a Gradle plugin.

This is my code

package com.example.lenovo.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
 import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ListView;
 import org.apache.commons.io.FileUtils;

 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;

  public class MainTimer extends AppCompatActivity {
    ArrayList<String> items;
    private ArrayAdapter<String> itemsAdapter;
    private ListView lvItems;
private Bundle savedInstanceState;

protected void onCreate(Bundle savedInstanceState) {
    this.savedInstanceState = savedInstanceState;
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // ADD HERE
        lvItems = (ListView) findViewById(R.id.lvItems);
        items = new ArrayList<String>();
    readItems();
        itemsAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, items);
        lvItems.setAdapter(itemsAdapter);
        items.add("First Item");
        items.add("Second Item");

        // ... existing code ...
        items.add("Second Item");
        // Setup remove listener method call
        setupListViewListener();
    }
public void showTimer(View view)
{
    String button_text;
    button_text = ((Button) view).getText().toString();
    if(button_text.equals("Pomodoro"))
    {
        Intent intent = new Intent(this,timer.class);
        startActivity(intent);
    }
}
public void onAddItem(View v) {

    EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
    String itemText = etNewItem.getText().toString();
    itemsAdapter.add(itemText);
    etNewItem.setText("");
    writeItems();
}

// Attaches a long click listener to the listview
private void setupListViewListener() {
    lvItems.setOnItemLongClickListener(
            new AdapterView.OnItemLongClickListener(){
                @Override
                public boolean onItemLongClick(AdapterView<?> adapter,
                                               View item, int pos, long id) {
                    // Remove the item within array at position
                    items.remove(pos);
                    // Refresh the adapter
                    itemsAdapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItems();
                    return true;
                }

            });
}
private void readItems() {
    File filesDir = getFilesDir();
    File todoFile = new File(filesDir, "todo.txt");
    try {
        items = new ArrayList<String>(FileUtils.readLines(todoFile));
    } catch (IOException e) {
        items = new ArrayList<String>();
    }
}

private void writeItems() {
    File filesDir = getFilesDir();
    File todoFile = new File(filesDir, "todo.txt");
    try {
        FileUtils.writeLines(todoFile, items);
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
    }

And this is my build.gradle dependencies

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',       {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-core-utils:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
testCompile 'junit:junit:4.12'
}

And, the last is I included my Graddle wrapper file

#Sat May 19 14:45:37 ICT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

用编译'org.apache.commons:commons-io:1.3.2'替换编译组:'org.apache.commons',名称:'commons-io',版本:'1.3.2'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM