0
我正在構建一個android應用程序。我的代碼顯示既沒有錯誤LogCat,但當我運行我的應用程序,我只得到對話框「加載....」,沒有更多。任何人都可以幫我解決這個問題嗎? 這裏是我的Manifest.xml排氣android從json沒有顯示任何錯誤的數據沒有顯示任何錯誤
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="movies.esprit.tn.edu.moviesparsingjson" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
AppController的
public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance=this;
}
public static synchronized AppController getmInstance(){
return mInstance;
}
public RequestQueue getmRequestQueue(){
if(mRequestQueue == null){
mRequestQueue=Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public ImageLoader getmImageLoader(){
getmRequestQueue();
if (mImageLoader==null){
mImageLoader = new ImageLoader(this.mRequestQueue, new BitmapCache());
}
return this.mImageLoader;
}
public <T> void addToRequestQueue (Request<T> request, String tag){
request.setTag((TextUtils.isEmpty(tag) ? TAG : tag));
getmRequestQueue().add(request);
}
private <T> void addToRequestQueue(Request<T> request) {
request.setTag(TAG);
getmRequestQueue().add(request);
}
public void cancelPendingRequest (Object tag){
if (mRequestQueue!=null){
mRequestQueue.cancelAll(tag);
}
}
}
這是我ItemAdapter(我的自定義適配器)
public class ItemAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Item> items;
private ImageLoader imageLoader = AppController.getmInstance().getmImageLoader();
public ItemAdapter(Activity activity, List<Item> items){
this .activity = activity;
this.items=items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return items.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null){
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if(convertView==null){
convertView = inflater.inflate(R.layout.custom_layout,null);
}
if (imageLoader==null){
imageLoader=AppController.getmInstance().getmImageLoader();
NetworkImageView imageView = (NetworkImageView) convertView.findViewById(R.id.thumbnail);
TextView title = (TextView) convertView.findViewById(R.id.titile);
TextView rating = (TextView) convertView.findViewById(R.id.rating);
Item.ResultsEntity item = (Item.ResultsEntity) getItem(position);
imageView.setImageUrl(item.getPoster_120x171(),imageLoader);
title.setText(String.valueOf(item.getTitle()));
rating.setText(String.valueOf(item.getRating()));
}
return convertView;
}
}
這是我mainActivity
public class MainActivity extends AppCompatActivity {
private static final String url = "http://api-public.guidebox.com/v1.43/Tunisia/rKgEWJbFg0kgEHrcGXPKhPDo0XtTafyC/movies/all/250/250";
private ProgressDialog dialog;
private List<Item> array=new ArrayList<Item>();
private ListView listView;
private ItemAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list_item);
adapter = new ItemAdapter(this, array);
listView.setAdapter(adapter);
dialog = new ProgressDialog(this);
dialog.setMessage("Loading.... ");
dialog.show();
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray jsonArray) {
hideDialog();
for (int i = 0; i<jsonArray.length(); i++){
try {
JSONObject obj = jsonArray.getJSONObject(i);
Item.ResultsEntity item = new Item.ResultsEntity();
item.setTitle(obj.getString("title"));
item.setPoster_120x171(obj.getString("poster_120x171"));
item.setRating(obj.getString("rating"));
}catch (JSONException ex){
ex.printStackTrace();
}
}
adapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
AppController.getmInstance().addToRequestQueue(jsonArrayRequest,url);
}
public void hideDialog(){
if (dialog!=null){
dialog.dismiss();
dialog=null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
最後,這是logcat的
05-12 03:22:28.582 813-813/movies.esprit.tn.edu.moviesparsingjson I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
05-12 03:22:28.622 813-813/movies.esprit.tn.edu.moviesparsingjson I/SELinux﹕ Function: selinux_android_load_priority , spota verifySig and checkHash pass. priority version is VE=SEPF_SM-G3815_4.4.2_0046
05-12 03:22:28.622 813-813/movies.esprit.tn.edu.moviesparsingjson E/dalvikvm﹕ >>>>> Normal User
05-12 03:22:28.622 813-813/movies.esprit.tn.edu.moviesparsingjson E/dalvikvm﹕ >>>>> movies.esprit.tn.edu.moviesparsingjson [ userId:0 | appId:10201 ]
05-12 03:22:28.622 813-813/movies.esprit.tn.edu.moviesparsingjson D/dalvikvm﹕ Late-enabling CheckJNI
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson I/dalvikvm﹕ Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson W/dalvikvm﹕ VFY: unable to resolve interface method 14536: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson I/dalvikvm﹕ Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson W/dalvikvm﹕ VFY: unable to resolve interface method 14540: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
05-12 03:22:28.862 813-813/movies.esprit.tn.edu.moviesparsingjson D/dalvikvm﹕ VFY: replacing opcode 0x72 at 0x0002
05-12 03:22:28.893 813-813/movies.esprit.tn.edu.moviesparsingjson I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
05-12 03:22:28.893 813-813/movies.esprit.tn.edu.moviesparsingjson W/dalvikvm﹕ VFY: unable to resolve virtual method 420: Landroid/content/res/TypedArray;.getChangingConfigurations()I
05-12 03:22:28.893 813-813/movies.esprit.tn.edu.moviesparsingjson D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
05-12 03:22:28.893 813-813/movies.esprit.tn.edu.moviesparsingjson I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
05-12 03:22:28.893 813-813/movies.esprit.tn.edu.moviesparsingjson W/dalvikvm﹕ VFY: unable to resolve virtual method 442: Landroid/content/res/TypedArray;.getType (I)I
05-12 03:22:28.893 813-813/movies.esprit.tn.edu.moviesparsingjson D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
05-12 03:22:28.963 813-813/movies.esprit.tn.edu.moviesparsingjson D/AbsListView﹕ Get MotionRecognitionManager
05-12 03:22:29.113 813-813/movies.esprit.tn.edu.moviesparsingjson I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: Nondeterministic_AU_msm8960_KK_2.7_RB1__release_AU()
OpenGL ES Shader Compiler Version: 17.01.12.SPL
Build Date: 03/25/14 Tue
Local Branch:
Remote Branch: quic/kk_2.7_rb1.32
Local Patches: NONE
Reconstruct Branch: NOTHING
05-12 03:22:29.143 813-813/movies.esprit.tn.edu.moviesparsingjson D/OpenGLRenderer﹕ Enabling debug mode 0
05-12 03:22:29.153 813-813/movies.esprit.tn.edu.moviesparsingjson D/ProgressBar﹕ updateDrawableBounds: left = 0
05-12 03:22:29.153 813-813/movies.esprit.tn.edu.moviesparsingjson D/ProgressBar﹕ updateDrawableBounds: top = 0
05-12 03:22:29.153 813-813/movies.esprit.tn.edu.moviesparsingjson D/ProgressBar﹕ updateDrawableBounds: right = 72
05-12 03:22:29.153 813-813/movies.esprit.tn.edu.moviesparsingjson D/ProgressBar﹕ updateDrawableBounds: bottom = 72
在*調試模式下運行你的應用程序*你可能會知道它在哪裏不工作 –
我想我有一個線程問題,因爲它告訴我,有「太多的工作」語句 –