简体   繁体   English

如何修复AsyncTask?

[英]How to fix AsyncTask?

In the past my app used to run correctly, but now the app has started giving me an error and it isn't responding whenever I try to open it up. 过去,我的应用曾经正常运行,但是现在,该应用开始出现错误,并且每次尝试打开它都没有响应。 What I'm trying to do here in the code is to get objects from Parse.com. 我要在代码中执行的操作是从Parse.com获取对象。 I currently have three tabs in my app and this is the code for the second tab. 我的应用程序中目前有三个标签,这是第二个标签的代码。 Here's the code: UPDATE: I managed to get the app working. 这是代码: 更新:我设法使应用程序正常工作。 The problem was I was assigning a Parsefile the wrong value. 问题是我为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;

} }

And here is the logcat error that keeps on appearing whenever I run the code: 每当我运行代码时,都会不断出现以下logcat错误:

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

Looks like some of your files are not getting compiled. 看起来您的某些文件未得到编译。 Last time I had this problem, I deleted app/build folder and let the Gradle build the project again. 上次遇到此问题时,我删除了app/build文件夹,然后让Gradle再次构建项目。 That worked for me. 那对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命异常:AsyncTask#1怎么修复? - FATAL EXCEPTION: AsyncTask #1 how fix? 如何修复致命异常:AsyncTask#1 doinbackground? - How to fix FATAL EXCEPTION: AsyncTask #1 doinbackground? 如何在AsyncTask中发送电子邮件时解决错误 - How to fix an error when sending email in AsyncTask 如何使用AsyncTask修复Android中的NetworkOnMainThreadException - How to fix NetworkOnMainThreadException in Android by using AsyncTask 如何解决替换 AsyncTask 以连接套接字的问题? - How to fix the Issue with replacing AsyncTask to connect socket? 我该如何修复Asynctask类的publishupdate方法 - how could I fix publishupdate method of Asynctask class 试图弄清楚为什么“ AsyncTask”无法正常工作以及如何解决 - Trying to figure out why “AsyncTask” is not working like I expect and How to fix it 问题,如何修复从Android中的URL获取JSON?Onclicklistener? AsyncTask? OnPostExecute? - issue, how Fix get JSON from URL in android?, Onclicklistener? AsyncTask? OnPostExecute? 如何修复由 Caused by: java.lang.NumberFormatException: For input string: "pets" 引起的 Asynctask 错误 - How to fix Asynctask error caused by Caused by: java.lang.NumberFormatException: For input string: "pets" 是否可以替代AsyncTask或如何重新启动AsyncTask? - Is any alternative to AsyncTask or how to restart AsyncTask?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM