android项目youtube客户端中,我采用google提供的第三方jar包,在java工程里运行一点问题都没有,为何在android模拟器中跑起来抛出错误 Could not find class 'com.google.gdata.client.youtube.YouTubeService', referenced from method com.hisoft.MainActivity$1.onClick
java.lang.NoClassDefFoundError: com.google.gdata.client.youtube.YouTubeService
YouTubeService类为何找不到呢?请高手指点
具体代码如下:package com.niit;import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.youtube.VideoFeed;
import com.google.gdata.util.ServiceException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MainActivity extends Activity {
private Button bt; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt = (Button) findViewById(R.id.button01);
bt.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Log.i("title", "hello");
YouTubeService myService = new YouTubeService(
"gdataSample-YouTube-1");
Log.i("title", "hello2");
String url = "https://gdata.youtube.com/feeds/api/videos?start- index=1&max-results=5&prettyprint=true&q=football";
try {
Log.i("title", "abcc");
VideoFeed videoFeed = myService.getFeed(new URL(url),
VideoFeed.class);
String title = videoFeed.getTitle().getPlainText(); Log.i("title", title);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} }
});
}
}
java.lang.NoClassDefFoundError: com.google.gdata.client.youtube.YouTubeService
YouTubeService类为何找不到呢?请高手指点
具体代码如下:package com.niit;import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.youtube.VideoFeed;
import com.google.gdata.util.ServiceException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MainActivity extends Activity {
private Button bt; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt = (Button) findViewById(R.id.button01);
bt.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Log.i("title", "hello");
YouTubeService myService = new YouTubeService(
"gdataSample-YouTube-1");
Log.i("title", "hello2");
String url = "https://gdata.youtube.com/feeds/api/videos?start- index=1&max-results=5&prettyprint=true&q=football";
try {
Log.i("title", "abcc");
VideoFeed videoFeed = myService.getFeed(new URL(url),
VideoFeed.class);
String title = videoFeed.getTitle().getPlainText(); Log.i("title", title);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} }
});
}
}
Intent Intentser = new Intent(this, YouTubeService.class);
this.startService(Intentser);
谢谢,加这句不行吧?。我不需要启动服务,YuTubeService是google第三方jar包里 给我们封装好的类有没有高手啊???赐教!!!
楼主的第三方jar包不会叫android.jar吧
gdata-2.2.1-alpha.jar gdata-core-1.0.jargdata-core-1.0.jar gdata-youtube-meta-2.0.jar等