即使我在依赖项

时间:2018-05-21 13:28:54

标签: java android

这是我的问题。 我收到两条错误消息

  1. “无法重新启动FileUtils”

  2. 未找到等级DSL方法:'compile()'

  3. (+)项目可能正在使用不包含该方法的Gradle版本,并且该版本可能缺少Gradle插件。

  4. 这是我的代码

    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();
        }
        }
        }
    

    这是我的build.gradle依赖项

    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'
    }
    

    而且,最后一个是我包含了我的Graddle包装文件

    #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
    

1 个答案:

答案 0 :(得分:0)

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