-3

別のパッケージ内のクラスのパブリック メソッドを呼び出そうとしています。私はすでにパッケージをインポートしているので、それは問題ではありません。私は日食を使用していますが、以下のエラーが発生しています。

コード:

public class BookView extends LinearLayout
   implements TextToSpeech.OnInitListener
   {
   private static final String LOGTAG = "BookView";
   private EPubWebView afd_webView;
   private Context afd_curContext;
  private FrameLayout afd_tableContentView;
  private String afd_cachePath = "";
  private EPubDriver afd_epubDriver;
  private AdView adView;
  private int currentPageNum = 1;
  private int totalPages;
  private int current_chapter;
  private int current_percent;
  private int pIndex;
  private int sIndex;
  private int size;
  private int chapterSize;
  private int bookSize;
  private String clickBk;
  private String bookPath;
  private String mDir = "/sdcard";
  private List<Map<String, Object>> mDataList;
  private ListView bookListView;
  private Handler handler = new Handler();
  private PopupWindow mBooksWindow;
  private int andVersion;
  private TextToSpeech tts;
  private final String errorMessage = "Download Error!";
  private boolean downloadCancel = false;
  private boolean isDownloading = false;

  public BookView(Context context, AttributeSet attrs)
  {
    super(context, attrs);
    setOrientation(1);
    this.afd_curContext = context;
    this.handler.postDelayed(new Runnable()
    {
      public void run()
      {
    BookView.this.doAdMob();
      }
    }
    , 10000L);

    this.tts = new TextToSpeech(context, this);

    this.afd_webView = new EPubWebView(context);
    DisplayMetrics metrics = new DisplayMetrics();
    ((Activity)context).getWindowManager().getDefaultDisplay()
      .getMetrics(metrics);

    LayoutInflater inflater = (LayoutInflater)context
  .getSystemService("layout_inflater");
    inflater.inflate(R.layout.afd_bookview, this);
    init();
  }

  public void jsImportBook(String epubBookPath) {
  if (!BookView.this.importBook(epubBookPath))
    return;
  BookView.this.createBookshelf();
}
}

以下の呼び出し方法は正しいですか?

 public void importnewbook(String epubBookPath) {

BookView v = new BookView();
    result = v.jsImportBook(epubBookPath); 
}

私が得ているエラー: 1) コンストラクタ BookView() は未定義です 2) メソッド jsImportBook(String) は型 BookView に対して未定義です

4

2 に答える 2

2

自分で何も指定していない場合、コンパイラはデフォルトで引数なしのコンストラクターを追加することに注意してください。

しかし、文字列を追加すると、コンパイラはあなたが何をしているのかを知っていると想定し、何のアクションも起こしません。つまり、引数なしのコンストラクターがないことを意味します。必要な場合は、それを定義する必要があります。

要するに:

1) 何もしないと、引数なしのコンストラクターが得られます。2) コンストラクターを追加すると、それですべてです。コンパイラーは他に何も追加しません。

そしてもちろん、定義したメソッドが期待する型を返すことを常に確認してください。

于 2013-05-21T15:33:01.843 に答える