Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何修复异步任务?_Android_Android Asynctask - Fatal编程技术网

Android 如何修复异步任务?

Android 如何修复异步任务?,android,android-asynctask,Android,Android Asynctask,过去我的应用程序运行正常,但现在该应用程序开始给我一个错误,每当我尝试打开它时,它都没有响应。我在代码中试图做的是从Parse.com获取对象。我的应用程序中目前有三个选项卡,这是第二个选项卡的代码。 代码如下: 更新:我设法让应用程序正常运行。问题是我给Parsefile分配了错误的值 public class TwoFragment extends Fragment{ public TwoFragment() { // Required empty public construct

过去我的应用程序运行正常,但现在该应用程序开始给我一个错误,每当我尝试打开它时,它都没有响应。我在代码中试图做的是从Parse.com获取对象。我的应用程序中目前有三个选项卡,这是第二个选项卡的代码。 代码如下: 更新:我设法让应用程序正常运行。问题是我给Parsefile分配了错误的值

public class TwoFragment extends Fragment{

public TwoFragment() {
    // Required empty public constructor
}


GridView gridview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
GridViewAdapter adapter;
private List<GameList> gamearraylist = null;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    new RemoteDataTask().execute();

}

// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(getContext());
        // Set progressdialog title
        mProgressDialog.setTitle("Place Holder Title");
        // Set progressdialog message
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // Create the array
        gamearraylist = new ArrayList<GameList>();
        try {
            // Locate the class table named "SamsungPhones" in Parse.com
            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                    "GamesList");
            // Locate the column named "position" in Parse.com and order list
            // by ascending
            query.orderByAscending("position");
            ob = query.find();
            for (ParseObject country : ob) {
                ParseFile image = (ParseFile) country.get("games");
                GameList map = new GameList();
                map.setGame(image.getUrl());
                gamearraylist.add(map);
            }
        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // Locate the gridview in gridview_main.xml
        gridview = (GridView) getView().findViewById(R.id.gridView);

        // Pass the results into ListViewAdapter.java
        adapter = new GridViewAdapter(getContext(),
                gamearraylist);
        // Binds the Adapter to the ListView
        gridview.setAdapter(adapter);
        // Close the progressdialog
        mProgressDialog.dismiss();
    }
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_two,container,false);
    GridView gridView = (GridView) view.findViewById(R.id.gridView);


    gridView.setAdapter(new ImageAdapter1(view.getContext()));

    return view;

} }

看起来您的一些文件没有被编译。上次我遇到这个问题时,我删除了
app/build
文件夹,让Gradle重新构建项目。这对我很有用。

你是否同时添加了
编译'com.parse.bolts:bolts android:1.+'
编译'com.parse:parse android:1.+'
?是的。刚刚加上这两个,现在我得到另一个错误。错误:任务“:app:dexDebug”的执行失败。“>com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:process'command'C:\Program Files\Java\jdk1.8.0_25\bin\Java.exe''以非零退出值2Alright结束。改变了一些事情,现在开始工作了。
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime: Process: ope.playingwithtabs, PID: 7054
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at android.os.AsyncTask$3.done(AsyncTask.java:309)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:  Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lbolts/Task;
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.checkIfRunning(ParseQuery.java:952)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:1129)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.findAsync(ParseQuery.java:1193)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.findInBackground(ParseQuery.java:1161)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.find(ParseQuery.java:981)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at ope.playingwithtabs.TwoFragment$RemoteDataTask.doInBackground(TwoFragment.java:79)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at ope.playingwithtabs.TwoFragment$RemoteDataTask.doInBackground(TwoFragment.java:53)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at android.os.AsyncTask$2.call(AsyncTask.java:295)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:  Caused by: java.lang.ClassNotFoundException: Didn't find class "bolts.Task" on path: DexPathList[[zip file "/data/app/ope.playingwithtabs-2/base.apk"],nativeLibraryDirectories=[/data/app/ope.playingwithtabs-2/lib/x86, /vendor/lib, /system/lib]]
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.checkIfRunning(ParseQuery.java:952) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.doWithRunningCheck(ParseQuery.java:1129) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.findAsync(ParseQuery.java:1193) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.findInBackground(ParseQuery.java:1161) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at com.parse.ParseQuery.find(ParseQuery.java:981) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at ope.playingwithtabs.TwoFragment$RemoteDataTask.doInBackground(TwoFragment.java:79) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at ope.playingwithtabs.TwoFragment$RemoteDataTask.doInBackground(TwoFragment.java:53) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at android.os.AsyncTask$2.call(AsyncTask.java:295) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.Thread.run(Thread.java:818) 
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:  Suppressed: java.lang.ClassNotFoundException: bolts.Task
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.Class.classForName(Native Method)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:          ... 14 more
03-20 17:09:12.478 7054-7079/ope.playingwithtabs E/AndroidRuntime:  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
03-20 17:09:13.101 7054-7078/ope.playingwithtabs E/Surface: getSlotFromBufferLocked: unknown buffer: 0xabee5fe0
03-20 17:09:13.118 7054-7078/ope.playingwithtabs E/Surface: getSlotFromBufferLocked: unknown buffer: 0xabee67c0