gpt4 book ai didi

java - 运行时异常: could not find class

转载 作者:行者123 更新时间:2023-12-01 04:32:45 24 4
gpt4 key购买 nike

当我尝试测试我的应用程序时,突然出现意外异常,但我还不知道原因,请帮助我找到错误。 (错误是:找不到类“com.example.MyPagerAdapter”)

这是我在第二个 Activity 中的代码

注意:此应用程序仅测试滑动,我只是从 MyPagerAdapter 类定义一个适配器,然后定义一个像这样的 ViewPager

 ViewPager   myPager   = (ViewPager) findViewById(R.id.home_pannels_pager);

然后设置适配器和当前项=0

 package com.example.tstswipe;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.webkit.WebView.FindListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyPagerAdapter extends PagerAdapter {

// State number of pages
public int getCount() {
return 5;
}

// Set each screen's content
public Object instantiateItem(View container, int position) {
Context context = container.getContext();
LinearLayout layout = new LinearLayout(context);
// Add elements
TextView textItem = new TextView(context);


Button buttonItem = new Button(context);
buttonItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("com.phone");
// myFancyMethod(v);
}
});


switch (position) {
case 0:
textItem.setText("First Screen");
break;
case 1:
textItem.setText("Second Screen");
break;
case 2:
textItem.setText("Third Screen");
break;


case 3:
textItem.setText("Fourth Screen");
break;
case 4:
textItem.setText("Fifth Screen");
break;
}
layout.addView(textItem);
((ViewPager) container).addView(layout, 0); // This is the line I added
return layout;
}
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
public Parcelable saveState() {
return null;
}

}

最佳答案

您指出错误是 could not find class "com.example.MyPagerAdapter"但您发布的类的完全限定名称是 com.example.tstswipe.MyPagerAdapter .

关于java - 运行时异常: could not find class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17784629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com