こんにちは、私は Android プログラミングが初めてで、理解できない 2 つのエラーがあります。問題をグーグルで検索してみましたが、まだうまくいかないので、最後の手段はここにあるべきです! あるフラグメントから別のフラグメントに移動するためのスワイプ ジェスチャを備えた複数のタブを持つ Android ランチャーを作成しています。shelfviewactivity を除いて、すべての画面が正常に動作しています (アクティビティがフラグメントであると表示されていても)。
これらは、修正方法がわからない2つのエラーです。
Multiple markers at this line
- The method setContentView(int) is undefined for the type
ShelfViewActivity
- The method setContentView(int) is undefined for the type
ShelfViewActivity
error2:
The constructor ShelfViewActivity.VerticalAdapter(ShelfViewActivity, int, ArrayList<ArrayList<BookItem>>) is
undefined
ShelfViewActivity は次のとおりです。
package com.d4a.tobias;
import java.util.ArrayList;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class ShelfViewActivity extends ListFragment {
/** Called when the activity is first created. */
private VerticalAdapter verListAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.main, container, false);
}
/*
* Calling Library & BookItem classes for create list of groups
* groupbyArrayBookItem return back array of array of items
*/
Library lb = new Library();{
for (BookItem item : BookItem.ALL_BOOKS) {
lb.addBookItem(item);
} //line 32
ArrayList<ArrayList<BookItem>> groupList = new ArrayList<ArrayList<BookItem>>();
groupList = lb.groupbyArrayBookItem(Library.AUTHOR);
verListAdapter = new VerticalAdapter(getActivity(), R.layout.bookrow, groupList);
setListAdapter(verListAdapter);
verListAdapter.notifyDataSetChanged();
}
/**
* This class add a list of ArrayList to ListView that it include multi
* items as bookItem.
*/
private class VerticalAdapter extends ArrayAdapter<ArrayList<BookItem>> {
private int resource;
public VerticalAdapter(Context _context, int _ResourceId,
ArrayList<ArrayList<BookItem>> _items) {
super(_context, _ResourceId, _items); //line 52
this.resource = _ResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView;
if (convertView == null) {
rowView = LayoutInflater.from(getContext()).inflate(resource,
null);
} else {
rowView = convertView;
}
HorizontalListView hListView = (HorizontalListView) rowView
.findViewById(R.id.subListview);
HorizontalAdapter horListAdapter = new HorizontalAdapter(
getContext(), R.layout.item, getItem(position));
hListView.setAdapter(horListAdapter);
return rowView;
}
}
/*
* This class add some items to Horizontal ListView this ListView include
* several bookItem.
*/
private class HorizontalAdapter extends ArrayAdapter<BookItem> {
private int resource;
public HorizontalAdapter(Context _context, int _textViewResourceId,
ArrayList<BookItem> _items) {
super(_context, _textViewResourceId, _items);
this.resource = _textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View retval = LayoutInflater.from(getContext()).inflate(
this.resource, null);
TextView topText = (TextView) retval.findViewById(R.id.title);
TextView bottomText = (TextView) retval
.findViewById(R.id.author);
topText.setText(getItem(position).getAuthor());
bottomText.setText(getItem(position).getTitle());
return retval;
}
}
}
編集: アプリは起動するようになりましたが、シェルフ ビュー アクティビティでクラッシュします
logcat は次のとおりです。
11-11 17:17:44.500: E/AndroidRuntime(23305): FATAL EXCEPTION: main
11-11 17:17:44.500: E/AndroidRuntime(23305): Process: com.d4a.tobias, PID: 23305
11-11 17:17:44.500: E/AndroidRuntime(23305): java.lang.NullPointerException
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.widget.ArrayAdapter.init(ArrayAdapter.java:310)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.widget.ArrayAdapter.<init>(ArrayAdapter.java:153)
11-11 17:17:44.500: E/AndroidRuntime(23305): at com.d4a.tobias.ShelfViewActivity$VerticalAdapter.<init>(ShelfViewActivity.java:52)
11-11 17:17:44.500: E/AndroidRuntime(23305): at com.d4a.tobias.ShelfViewActivity.<init>(ShelfViewActivity.java:36)
11-11 17:17:44.500: E/AndroidRuntime(23305): at it.gmariotti.android.examples.googleaccount.MainFrag$MyAdapter.getItem(MainFrag.java:80)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:95)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:649)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.support.v4.view.ViewPager.populate(ViewPager.java:783)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1280)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1176)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13315)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13372)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13268)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13372)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13268)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13372)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13268)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13372)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3077)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13268)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.View.getDisplayList(View.java:13372)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.HardwareRenderer$GlRenderer.buildDisplayList(HardwareRenderer.java:1570)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1449)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2379)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2251)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1881)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.Choreographer.doFrame(Choreographer.java:532)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.os.Handler.handleCallback(Handler.java:733)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.os.Handler.dispatchMessage(Handler.java:95)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.os.Looper.loop(Looper.java:137)
11-11 17:17:44.500: E/AndroidRuntime(23305): at android.app.ActivityThread.main(ActivityThread.java:4998)
11-11 17:17:44.500: E/AndroidRuntime(23305): at java.lang.reflect.Method.invokeNative(Native Method)
11-11 17:17:44.500: E/AndroidRuntime(23305): at java.lang.reflect.Method.invoke(Method.java:515)
11-11 17:17:44.500: E/AndroidRuntime(23305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-11 17:17:44.500: E/AndroidRuntime(23305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-11 17:17:44.500: E/AndroidRuntime(23305): at dalvik.system.NativeStart.main(Native Method)
11-11 17:17:51.318: E/ACDB-LOADER(177): Error: ACDB AudProc vol returned = -8
私が間違っていることを示すためのリンクや参照は素晴らしいでしょう
事前に1,000,000回ありがとう