Aller au contenu

Problème JavaNullPointeur API Youtube


Maxime Gens

Recommended Posts

Bonjour :D , j'espère que vous allez pouvoir m'aider car je bute sur ce problème depuis un bon moment. J'ai développé une application avec l'API Youtube afin de récupérer les vidéos depuis un compte, l'application marche très bien sur mon téléphone (Galaxy SCL i9003) mais ne fonction pas sur l'émulateur ni sur un Galaxy Y ????

Après avoir un peu chercher il me semble que c'est un problème de pointeur null (le substring me fait bugger apparement) o_O

Niveau libs j'ai dans mon projet :

  • activation.jar
  • gdata-client1.0.jar
  • puce>gdata-client1.0-meta.jar
  • gdata-core1.0.jar
  • gdata-media1.0.jar
  • gdata-youtube2.0.jar
  • gdata-youtube-meta-2.0.jar
  • guava-12.0.jar mail-1.4.1.jar

Voici mon code

public String getIdVideo(){
try {
Log.v("LOG", "4");
      YouTubeService service = new YouTubeService("LetsPlayCastrix-Actualite");
      Log.v("LOG", "5");
  YouTubeQuery query = new YouTubeQuery(new URL(Tools.YoutubeChaineAuteur));
  Log.v("LOG", "6");
  VideoFeed video = service.query(query, VideoFeed.class);
  if(video != null)
  return video.getEntries().get(0).getId().substring(27);
      }catch (MalformedURLException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  } catch (ServiceException e) {
  e.printStackTrace();
  }
return "perdu";
}

   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.actualite);

       //idVideo = "mPG7lIoDguU";
       idVideo = getIdVideo();
       Toast.makeText(Actualite.this, idVideo, Toast.LENGTH_SHORT).show();
note = (TextView)findViewById(R.actualite.note);
dernierVideo = (TextView)findViewById(R.actualite.dernierevideo);
titreVideo = (TextView)findViewById(R.actualite.titrevideo);
note.setText(Tools.lectureFichierNote());
Log.v("LOG", "7");
videoDuMoment = (ImageView)findViewById(R.actualite.lancervideo);
videoDuMoment.setImageDrawable(Tools.getPicture(Tools.BuildHrefImageYoutube(idVideo)));
titreVideo.setText(Tools.getTitleLastVideo());

Log.v("LOG", "8");
  videoDuMoment.setonclickListener(new onclickListener(){
public void onclick(View arg0) {
Log.v("LOG", "9");
String lienVideoToutube = Tools.BuildHrefYoutube(idVideo);
Intent intentYoutube = new Intent(Intent.ACTION_VIEW,Uri.parse(lienVideoToutube));
startActivity(intentYoutube);
}
});
}
}

Mon LOGCAT

07-16 13:51:52.294: I/global(467): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
07-16 13:51:52.294: V/LOG(467): 7
07-16 13:51:52.864: D/dalvikvm(467): GC freed 19825 objects / 1103648 bytes in 98ms
07-16 13:51:53.184: D/dalvikvm(467): GC freed 12501 objects / 934704 bytes in 92ms
07-16 13:51:53.484: D/dalvikvm(467): GC freed 11412 objects / 688560 bytes in 96ms
07-16 13:51:53.644: D/AndroidRuntime(467): Shutting down VM
07-16 13:51:53.644: W/dalvikvm(467): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
07-16 13:51:53.644: E/AndroidRuntime(467): Uncaught handler: thread main exiting due to uncaught exception
07-16 13:51:53.664: E/AndroidRuntime(467): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maximeGens.letsPlayCastrix/com.maximeGens.letsPlayCastrix.LetsPlayActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maximeGens.letsPlayCastrix/com.maximeGens.letsPlayCastrix.Actualite}: java.lang.NullPointerException
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.access$2200(ActivityThread.java:119)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.os.Looper.loop(Looper.java:123)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.main(ActivityThread.java:4363)
07-16 13:51:53.664: E/AndroidRuntime(467):         at java.lang.reflect.Method.invokeNative(Native Method)
07-16 13:51:53.664: E/AndroidRuntime(467):         at java.lang.reflect.Method.invoke(Method.java:521)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-16 13:51:53.664: E/AndroidRuntime(467):         at dalvik.system.NativeStart.main(Native Method)
07-16 13:51:53.664: E/AndroidRuntime(467): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maximeGens.letsPlayCastrix/com.maximeGens.letsPlayCastrix.Actualite}: java.lang.NullPointerException
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.widget.TabHost.setCurrentTab(TabHost.java:320)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.widget.TabHost.addTab(TabHost.java:213)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.maximeGens.letsPlayCastrix.LetsPlayActivity.creationOnglets(LetsPlayActivity.java:32)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.maximeGens.letsPlayCastrix.LetsPlayActivity.onCreate(LetsPlayActivity.java:41)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-16 13:51:53.664: E/AndroidRuntime(467):         ... 11 more
07-16 13:51:53.664: E/AndroidRuntime(467): Caused by: java.lang.NullPointerException
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.wireformats.AltRegistry.lookupType(AltRegistry.java:190)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.Service.parseResponseData(Service.java:2134)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.Service.getFeed(Service.java:1136)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.Service.getFeed(Service.java:1077)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:676)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.Service.query(Service.java:1237)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.google.gdata.client.Service.query(Service.java:1178)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.maximeGens.letsPlayCastrix.Tools.getTitleLastVideo(Tools.java:66)
07-16 13:51:53.664: E/AndroidRuntime(467):         at com.maximeGens.letsPlayCastrix.Actualite.onCreate(Actualite.java:65)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 13:51:53.664: E/AndroidRuntime(467):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
07-16 13:51:53.664: E/AndroidRuntime(467):         ... 21 more
07-16 13:51:53.704: I/dalvikvm(467): threadid=7: reacting to signal 3
07-16 13:51:53.704: E/dalvikvm(467): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
07-16 13:53:26.934: I/Process(467): Sending signal. PID: 467 SIG: 9

Lien vers le commentaire
Partager sur d’autres sites

Oui voilà le code qui pause problème, je te remercie de ta réponse =)

public static String getTitleLastVideo(){

     try {
      YouTubeService service1 = new YouTubeService("LetsPlayCastrix-Actualite2");
  YouTubeQuery query1 = new YouTubeQuery(new URL(Tools.YoutubeChaineAuteur));;
  VideoFeed video1 = service1.query(query1, VideoFeed.class);
  if(video1 != null)
  return(video1.getEntries().get(0).getTitle().getPlainText());
      } catch (MalformedURLException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  } catch (ServiceException e) {
  e.printStackTrace();
  }
     return null;
}

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...