Ikkatsu Manga Posted November 29, 2012 Share Posted November 29, 2012 Bonjour, Je suis actuellement en train de développer une application qui se connecte à MySql en utilisant php et JSon. Le problème c'est que pour le moment l'application fonctionne sur l'émulateur android mais pas sur un vrai terminal android. J'ai testé sur mon htc One x et sur une galaxy tab. L'application dispose de 2 activity. La premiere contient un bouton image. Lorsque l'on clique dessus, on passe à la seconde activity qui va récuperer les données de la base mysql et les affichés sur une listView. Sur un vrai terminal, c'est lors du clique sur le bouton de la première activity que l'on à un probleme et que l'application se termine. Est-ce que quelqu'un à une idée d'ou sa pourrait venir ? Link to comment Share on other sites More sharing options...
g123k Posted November 30, 2012 Share Posted November 30, 2012 Il faut que tu regardes le logcat pour voir d'où vient le problème tout simplement Sinon donnes une apk et je te dirais Link to comment Share on other sites More sharing options...
Ikkatsu Manga Posted November 30, 2012 Author Share Posted November 30, 2012 L'appli à fonctionner sur un galaxy s2. Je te transmet l'apk par mail.Je ne trouve toujours pas l'erreur. Je transmet mon code source. En espérant que quelqu'un pourra m'aider plus amplement. Je cherche mais en vain toujours pas trouvé d'ou viens mon problème. La seconde activity : package com.redone.ikkatsu_mangareader; import java.util.ArrayList; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.ListView; import android.support.v4.app.NavUtils; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.app.ListActivity; import android.content.Intent; import android.net.ParseException; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.Toast; public class ListChapter extends ListActivity { final String EXTRA_NAME = "manga_name"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_list_chapter); Intent intent = getIntent(); //ListView listChapter = (ListView) findViewById(R.id.listView1); ArrayList<String> items=new ArrayList<String>(); String result = null; InputStream is = null; JSONObject json_data=null; ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); try{ //commandes httpClient HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://app.ikkatsu-manga.com/listChapter.php?nom="+intent.getStringExtra(EXTRA_NAME)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch(Exception e){ Log.i("taghttppost",""+e.toString()); Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show(); } //conversion de la réponse en chaine de caractère try { BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8")); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result = sb.toString(); } catch(Exception e) { Log.i("tagconvertstr",""+e.toString()); } //recuperation des donnees json try{ JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { json_data = jArray.getJSONObject(i); items.add(json_data.getString("name")); } setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,android.R.id.text1,items)); } catch(JSONException e){ Log.i("tagjsonexp",""+e.toString()); } catch (ParseException e) { Log.i("tagjsonpars",""+e.toString()); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_list_chapter, menu); return true; } } Le xml de la seconde activity : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".ListChapter" > <ListView android:id="@+id/listView1" android:layout_width="0dip" android:layout_height="fill_parent" android:layout_weight="1" > </ListView> </LinearLayout> Android Manifest : <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.redone.ikkatsu_mangareader" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.INTERNET" /> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.redone.ikkatsu_mangareader.ListChapter" android:label="La liste des chapitres" > </activity> <activity android:name="com.redone.ikkatsu_mangareader.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> </manifest> Link to comment Share on other sites More sharing options...
g123k Posted December 1, 2012 Share Posted December 1, 2012 Quelques remarques : - Tu fais ta requête dans le thread principal. A éviter, car tu bloques l'UI pendant ce temps. Utilises une AsyncTask, un Thread... - Dans ton xml, si tu n'utilises pas réellement le poids, ne le mets pas. C'est utile dans d'autres cas. - Dans ton Manifest, tu peux remplacer le nom de tes Activity par .ListChapter par exemple. Tu n'es pas obligé d'écrire le package en entier Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.