JeremX Posted July 1, 2012 Share Posted July 1, 2012 Bonjour, je développe une application qui récupère des images depuis un serveur. J'ai une erreur qui m'empêche de compiler l'apk: GalleryTheme_android_galleryItemBackground cannot be resolved to a variable Voici le bout de code ou cela coince: public AddImgAdp(Context c) { cont = c; TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme); GalItemBg = a.getResourceId(GalleryTheme_android_galleryItemBackground, 0); a.recycle(); } Le fichier attrs.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="GalleryTheme"> <attr name="android:galleryItemBackground" /> </declare-styleable> </resources> J'ai fait des recherches sur le net et je ne suis pas le seul à avoir cette erreur, mais je ne trouve pas de réelle solution... Pourriez-vous m'aider s'il vous plait ? :) Link to comment Share on other sites More sharing options...
androïll Posted July 4, 2012 Share Posted July 4, 2012 Bonjour, essaye ça ;) : GalItemBg = a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); Link to comment Share on other sites More sharing options...
JeremX Posted July 4, 2012 Author Share Posted July 4, 2012 Bonjour Androïll, Merci pour ta réponse, je n'ai plus cette erreur. L'application se compile. Cependant, elle crashe dès qu'elle est lancée: j'ai les erreurs suivantes: 07-04 09:25:57.983: E/AndroidRuntime(789): FATAL EXCEPTION: main 07-04 09:25:57.983: E/AndroidRuntime(789): java.lang.IllegalStateException: Could not execute method of the activity 07-04 09:25:57.983: E/AndroidRuntime(789): at android.view.View$1.onClick(View.java:3591) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.view.View.performClick(View.java:4084) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.view.View$PerformClick.run(View.java:16966) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.os.Handler.handleCallback(Handler.java:615) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.os.Handler.dispatchMessage(Handler.java:92) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.os.Looper.loop(Looper.java:137) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.app.ActivityThread.main(ActivityThread.java:4745) 07-04 09:25:57.983: E/AndroidRuntime(789): at java.lang.reflect.Method.invokeNative(Native Method) 07-04 09:25:57.983: E/AndroidRuntime(789): at java.lang.reflect.Method.invoke(Method.java:511) 07-04 09:25:57.983: E/AndroidRuntime(789): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 07-04 09:25:57.983: E/AndroidRuntime(789): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 07-04 09:25:57.983: E/AndroidRuntime(789): at dalvik.system.NativeStart.main(Native Method) 07-04 09:25:57.983: E/AndroidRuntime(789): Caused by: java.lang.reflect.InvocationTargetException 07-04 09:25:57.983: E/AndroidRuntime(789): at java.lang.reflect.Method.invokeNative(Native Method) 07-04 09:25:57.983: E/AndroidRuntime(789): at java.lang.reflect.Method.invoke(Method.java:511) 07-04 09:25:57.983: E/AndroidRuntime(789): at android.view.View$1.onClick(View.java:3586) 07-04 09:25:57.983: E/AndroidRuntime(789): ... 11 more 07-04 09:25:57.983: E/AndroidRuntime(789): Caused by: android.os.NetworkOnMainThreadException 07-04 09:25:57.983: E/AndroidRuntime(789): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117) 07-04 09:25:57.983: E/AndroidRuntime(789): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 07-04 09:25:57.983: E/AndroidRuntime(789): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 07-04 09:25:57.983: E/AndroidRuntime(789): at java.net.InetAddress.getAllByName(InetAddress.java:214) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239) 07-04 09:25:57.983: E/AndroidRuntime(789): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 07-04 09:25:57.983: E/AndroidRuntime(789): at com.wordpress.jeremx.JeremXsAppActivity.setImage(JeremXsAppActivity.java:216) 07-04 09:25:57.983: E/AndroidRuntime(789): at com.wordpress.jeremx.JeremXsAppActivity.load_main(JeremXsAppActivity.java:122) Ce sont des erreurs que je n'avais pas avant d'intégrer une web gallery dans mon application. J'ai pourtant mis la permission pour Internet. Link to comment Share on other sites More sharing options...
androïll Posted July 4, 2012 Share Posted July 4, 2012 Verifie ces lignes : 07-04 09:25:57.983: E/AndroidRuntime(789): at com.wordpress.jeremx.JeremXsAppActivity.setImage(JeremXsAppActivity.java:216) 07-04 09:25:57.983: E/AndroidRuntime(789): at com.wordpress.jeremx.JeremXsAppActivity.load_main(JeremXsAppActivity.java:122) peux tu poster ces lignes de code? Link to comment Share on other sites More sharing options...
JeremX Posted July 17, 2012 Author Share Posted July 17, 2012 Bonjour Androïll, désolé pour ce retard mais je n'avais plus reçu de notifications par e-mail pour les réponses du coup je suis venu faire un up et je vois ton message. Voici les lignes de codes: Ligne 216: public void setImage(ImageView aView, URL aURL) { try { URLConnection conn = aURL.openConnection(); /* Ligne 216 */ conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, 8192); Bitmap bm = BitmapFactory.decodeStream(bis); bis.close(); is.close(); aView.setImageBitmap(bm); } catch (IOException e) { aView.setImageDrawable(mNoImage); Log.e("DVP Gallery", "Erreur téléchargement image URL : " + aURL.toString()); e.printStackTrace(); } } Ligne 122: mNoImage = this.getResources().getDrawable(R.drawable.error); mListImages = buildListImages(); imgView = (ImageView)findViewById(R.id.error); if (mListImages.size() <= 0){ imgView.setImageDrawable(mNoImage); } else { /* Ligne 122 */ setImage(imgView, mListImages.get(0)); } gallery1 = (Gallery) findViewById(R.id.gallery1); gallery1.setAdapter(new AddImgAdp(this)); gallery1.setSpacing(10); gallery1.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView parent, View v, int position, long id){ setImage(imgView, mListImages.get(position)); } }); } Les lignes où les erreurs sont signalées sont en dessous des commentaires dans le code. Je ne vois vraiment pas d'où cela vient... Désolé encore. Link to comment Share on other sites More sharing options...
JeremX Posted August 20, 2012 Author Share Posted August 20, 2012 Up Link to comment Share on other sites More sharing options...
chpil Posted August 22, 2012 Share Posted August 22, 2012 C'est simple, il te dit (NetworkOnMainThreadException) que tu ne peux pas faire de requêtes réseau dans le thread principal. Il faut que tu fasses tes traitements réseaux dans un thread séparé, via une AsyncTask par exemple. Link to comment Share on other sites More sharing options...
JeremX Posted August 26, 2012 Author Share Posted August 26, 2012 Merci pour ta réponse chpil. Je vais essayer de faire ça et je te tiens au courant. Merci. :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.