2016-03-20 39 views
0

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

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; 

} } 

这里是在不断出现,每当我运行代码的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 
+0

您是否同时添加了'compile'c​​om.parse.bolts:bolts-android:1。+''和 'compile'c​​om.parse:parse-android:1。+''? – GVillani82

+0

是的。刚刚添加这两个,现在我得到了另一个错误。错误:任务':app:dexDebug'的执行失败。 > com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\ Program Files \ Java \ jdk1.8.0_25 \ bin \ java.exe''已完成非零退出值2 – user3479469

+0

好的。改变了一些东西,现在它正在工作。 – user3479469

回答

0

看起来像你的一些文件都没有得到编译。上次我有这个问题,我删除app/build文件夹,让Gradle再次构建项目。这对我有效。