我的主要问题是我得到一个错误,说明:ImagePagerAdapter不能解析为类型
在第80行:
第80行是ImagePagerAdapter adapter=new ImagePagerAdapter()
我还收到一条警告:
输入Home。ThumbnailLoadedListener。ImagePagerAdapter从未在本地使用
我很确定,我的ImagePagerAdapter由于收尾括号放错了位置而无法联系到——我试过调整其中一些,但我只是在确定是哪一个导致了问题(或者可能是其他原因)上有点困难
我还遇到了其他一些错误,这些错误与大量代码(基本上是第二部分)未定义/未访问有关,但我99%确定这都与语法问题或放错括号有关。
ImagePagerAdapter cannot be resolved to a type line 80
ImagePagerAdapter cannot be resolved to a type line 80
ThumbnailListener cannot be resolved to a type line 225
The method onCreateOptionsMenu(Menu) is undefined for the type Object line 246
The method onConfigurationChanged(Configuration) is undefined for the type Object line 238
The method onOptionsItemSelected(MenuItem) is undefined for the type Object line 257
附笔。
我为大量的代码道歉——我只是不确定如果我只显示其中的一部分,是否有可能解决。
public class Home extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener,
YouTubeThumbnailView.OnInitializedListener {
public static final String API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXX";
public static final String VIDEO_ID = "o7VVHhK9zf0";
public static final String VIDEO1_ID = "xVHHJqntuXI";
public static final String VIDEO2_ID = "YWteQj_q3Ro";
public static final String VIDEO3_ID = "83ZgtqTw-mI";
public static final String VIDEO4_ID = "n5wMza29JwI";
private YouTubePlayer youTubePlayer;
private YouTubePlayerView youTubePlayerView;
private YouTubeThumbnailView youTubeThumbnailView1;
private YouTubeThumbnailView youTubeThumbnailView2;
private YouTubeThumbnailView youTubeThumbnailView3;
private YouTubeThumbnailView youTubeThumbnailView4;
private String[] drawerListViewItems;
private DrawerLayout drawerLayout;
private DrawerLayout mDrawerLayout;
private ListView drawerListView;
private ListView mDrawerList;
private ActionBarDrawerToggle actionBarDrawerToggle;
private ActionBarDrawerToggle mDrawerToggle;
private YouTubeThumbnailLoader thumbnailLoader;
private YouTubeThumbnailLoader youTubeThumbnailLoader;
private YouTubeThumbnailLoader youTubeThumbnailLoader1;
private YouTubeThumbnailLoader youTubeThumbnailLoader2;
private YouTubeThumbnailLoader youTubeThumbnailLoader3;
private boolean nextThumbnailLoaded;
ScrollView mainScrollView;
Button fav_up_btn1;
Button fav_dwn_btn1;
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbar_custom_view_home);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
// get list items from strings.xml
drawerListViewItems = getResources().getStringArray(R.array.items);
// get ListView defined in activity_main.xml
drawerListView = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
drawerListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_listview_item, drawerListViewItems));
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtubeplayerview);
youTubePlayerView.initialize(API_KEY, this);
mainScrollView = (ScrollView) findViewById(R.id.groupScrollView);
youTubeThumbnailView1 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview1);
youTubeThumbnailView1.initialize(API_KEY, this);
fav_up_btn1 = (Button) findViewById(R.id.fav_up_btn1);
fav_up_btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean favIsUp = fav_up_btn1
.getBackground()
.getConstantState()
.equals(getResources().getDrawable(
R.drawable.fav_up_btn1).getConstantState());
// set the background
fav_up_btn1
.setBackgroundResource(favIsUp ? R.drawable.fav_dwn_btn1
: R.drawable.fav_up_btn1);
}
});
youTubeThumbnailView1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO1_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
youTubeThumbnailView2 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview2);
youTubeThumbnailView2.initialize(API_KEY, this);
youTubeThumbnailView2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg1) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO2_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
youTubeThumbnailView3 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview3);
youTubeThumbnailView3.initialize(API_KEY, this);
youTubeThumbnailView3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg1) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO3_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
youTubeThumbnailView4 = (YouTubeThumbnailView) findViewById(R.id.youtubethumbnailview4);
youTubeThumbnailView4.initialize(API_KEY, this);
youTubeThumbnailView4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg1) {
if (youTubePlayer != null) {
youTubePlayer.cueVideo(VIDEO4_ID);
youTubePlayer.play();
mainScrollView.smoothScrollTo(0, 0);
}
}
});
}
@Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult result) {
}
@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
youTubePlayer = player;
if (!wasRestored) {
player.cueVideo(VIDEO_ID);
}
}
@Override
public void onInitializationFailure(YouTubeThumbnailView thumbnailView,
YouTubeInitializationResult error) {
}
@Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
YouTubeThumbnailLoader thumbnailLoader) {
this.thumbnailLoader = thumbnailLoader;
thumbnailLoader.setOnThumbnailLoadedListener(new ThumbnailListener());
}
private final class ThumbnailLoadedListener implements
YouTubeThumbnailLoader.OnThumbnailLoadedListener {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView arg0, String arg1) {
youTubeThumbnailLoader1.setVideo(VIDEO1_ID);
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// call ActionBarDrawerToggle.onOptionsItemSelected(), if it returns
// true
// then it has handled the app icon touch event
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] { R.drawable.classical_up_btn,
R.drawable.country_up_btn, R.drawable.dance_up_btn,
R.drawable.hiphop_up_btn };
public int getCount() {
return mImages.length;
}
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
public Object instantiateItem(ViewGroup container, int position) {
Context context = Home.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position,
Object object) {
((ViewPager) container).removeView((ImageView) object);
}
private final class ThumbnailListener implements
YouTubeThumbnailLoader.OnThumbnailLoadedListener {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView thumbnail,
String videoId) {
// nextThumbnailLoaded = true;
//
// if (activityResumed) {
// if (state.equals(State.LOADING_THUMBNAILS)) {
// flipNext();
// } else if (state.equals(State.VIDEO_FLIPPED_OUT)) {
// // load player with the video of the next thumbnail being
// flipped in
// state = State.VIDEO_LOADING;
// player.cueVideo(videoId);
}
@Override
public void onThumbnailError(YouTubeThumbnailView arg0,
ErrorReason arg1) {
// TODO Auto-generated method stub
}
}
}
public void onThumbnailError(YouTubeThumbnailView thumbnail,
YouTubeThumbnailLoader.ErrorReason reason) {
loadNextThumbnail();
}
private void loadNextThumbnail() {
nextThumbnailLoaded = false;
if (thumbnailLoader.hasNext()) {
thumbnailLoader.next();
} else {
thumbnailLoader.first();
}
}
}
}
您必须将创建选项菜单中的方法更改为:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
我正在使用eclipse,我需要在我的android活动中使用带有PagerSlidingAbstrip的滑动选项卡。解决方案必须是什么?
问题内容: 尝试遵循本教程:教程 尝试像这样使用 JSONParser : 但是Eclipse给了我。 该怎么办? 问题答案: JSONParser类在本教程的下方,它看起来像这样…… 我会考虑看看杰克逊图书馆通过http://jackson.codehaus.org/
我正在尝试将主题添加到我的项目中。它需要appcompat v7。 我按照Android开发者网站中提到的步骤添加了支持库。经过大量搜索,我知道支持库v4将与支持库v7冲突。 所以我从我的项目中删除了android库v4。因此,现在我得到了t错误()。 我必须做什么?请有人帮我解决这个问题。预先感谢
在我的testrunner类中,当使用时,我收到一条错误消息,说“cucumberoptions不能解析为类型”。我使用的是最新版本的eclipse cucumber依赖项。通过安装和卸载eclipse,通过降低cucumber依赖项版本,我已经尝试了所有可能的方法。 我的跑者班是:
我创建了一个RunTest类来使用Cucumber和JUnit运行测试场景。要运行之前的测试,我需要将RunWith类(@RunWith)导入到我的项目中,并将Cucumber.class作为参数传递。然后,类的RunWith参数识别更多传递给它的参数,不。eclipse将显示以下消息: 无法将此行类中的多个标记解析为类型。-Cucumber无法解析为类型。-注释@runwith必须定义属性值 我
问题内容: 这是我得到的错误: 这是我的代码: 另外,我在一个单独的类中声明了这一点: 是什么导致此错误,我该如何解决? 编辑:缩进,空格,命名约定和可读性问题已得到解决。 问题答案: 问题在于,这似乎是一个内部类(很难说,您的缩进是不好的),并且由于它不是静态的,因此您无法单独实例化它。 您要么需要自己创建一个类,要么使其成为一个类并将其实例化为(或者无论父类是什么,您的缩进在这里实际上都没有帮