これは私のコードです
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
public class CurrentActivity extends InfoActivity {
private ViewPager columnas;
private static int NUM_COLUMNAS = 4;
private Context cxt;
private ColumnAdapter miAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_current);
info();
cxt = this;
miAdapter = new ColumnAdapter();
columnas = (ViewPager) findViewById(R.id.columnas);
columnas.setAdapter(miAdapter);
TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
titleIndicator.setViewPager(columnas);
}
private class ColumnAdapter extends PagerAdapter {
@Override
public int getCount() {
return NUM_COLUMNAS;
}
@Override
public Object instantiateItem(View collection, int position) {
ScrollView v = (ScrollView) LayoutInflater.from(cxt).inflate(
R.layout.info, null);
if (position == 0) {
v = (ScrollView) LayoutInflater.from(cxt).inflate(
R.layout.info, null);
} else if (position == 1) {
v = (ScrollView) LayoutInflater.from(cxt).inflate(
R.layout.look, null);
} else if (position == 2) {
v = (ScrollView) LayoutInflater.from(cxt).inflate(
R.layout.touch, null);
} else if (position == 3) {
v = (ScrollView) LayoutInflater.from(cxt).inflate(
R.layout.tilt, null);
}
((ViewPager) collection).addView(v, 0);
return v;
}
@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((ScrollView) view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ScrollView) object);
}
@Override
public void finishUpdate(View arg0) {
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
@Override
public CharSequence getPageTitle(int position) {
String a = null;
TextView info = (TextView) findViewById(R.id.info_textview_info);
TextView look = (TextView) findViewById(R.id.info_textview_look);
TextView touch = (TextView) findViewById(R.id.info_textview_touch);
TextView tilt = (TextView) findViewById(R.id.info_textview_tilt);
if (position == 0) {
a = getResources().getString(R.string.info).toUpperCase();
info.setText((R.string.one_lev_info));
info.setGravity(Gravity.LEFT);
info.setTextSize(15);
} else if (position == 1) {
a = getResources().getString(R.string.look).toUpperCase();
look.setText((R.string.one_lev_look));
look.setGravity(Gravity.LEFT);
look.setTextSize(15);
} else if (position == 2) {
a = getResources().getString(R.string.touch).toUpperCase();
touch.setText((R.string.one_lev_look));
touch.setGravity(Gravity.LEFT);
touch.setTextSize(15);
} else if (position == 3) {
a = getResources().getString(R.string.tilt).toUpperCase();
tilt.setText((R.string.one_lev_look));
tilt.setGravity(Gravity.LEFT);
tilt.setTextSize(15);
}
return a;
}
}
わかりましたこれは、たとえば情報の私のレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<TextView
android:id="@+id/info_textview_look"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/look_no"
android:textColor="#4D4D4D"
android:textSize="25dp"
android:textStyle="normal" />
</ScrollView>
これは、次のテキストを含む XML です。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="one_lev_info">The shows a 1789</string>
<string name="one_lev_look">consisting of rhomboid</string>
</resources>
しかし、私がそれを実行すると、Javaファイルの関数getPageTitleの行にエラーが表示されます
touch.setText((R.string.one_lev_look));
しかし、Textview のタッチとチルトに関連するすべてを削除すると、問題ありません。だから私は3列しか持たないようにしましたが、3列目だけでまだ問題が発生しています。多分私は間違っています。
そして、これはエラーログです
07-30 08:40:09.204: E/AndroidRuntime(9115): FATAL EXCEPTION: main
07-30 08:40:09.204: E/AndroidRuntime(9115): java.lang.NullPointerException
07-30 08:40:09.204: E/AndroidRuntime(9115): at my.package.oh.yes.CurrentActivity$ColumnAdapter.getPageTitle(CurrentActivity.java:110)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.viewpagerindicator.TitlePageIndicator.getTitle(TitlePageIndicator.java:802)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.viewpagerindicator.TitlePageIndicator.calcBounds(TitlePageIndicator.java:639)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.viewpagerindicator.TitlePageIndicator.calculateAllBounds(TitlePageIndicator.java:616)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.viewpagerindicator.TitlePageIndicator.onDraw(TitlePageIndicator.java:336)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.View.draw(View.java:6970)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.View.draw(View.java:6973)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.View.draw(View.java:6973)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewGroup.drawChild(ViewGroup.java:1732)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1459)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.View.draw(View.java:6973)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.widget.FrameLayout.draw(FrameLayout.java:357)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1997)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewRoot.draw(ViewRoot.java:1600)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewRoot.performTraversals(ViewRoot.java:1321)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.view.ViewRoot.handleMessage(ViewRoot.java:1957)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.os.Looper.loop(Looper.java:150)
07-30 08:40:09.204: E/AndroidRuntime(9115): at android.app.ActivityThread.main(ActivityThread.java:4277)
07-30 08:40:09.204: E/AndroidRuntime(9115): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 08:40:09.204: E/AndroidRuntime(9115): at java.lang.reflect.Method.invoke(Method.java:507)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-30 08:40:09.204: E/AndroidRuntime(9115): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-30 08:40:09.204: E/AndroidRuntime(9115): at dalvik.system.NativeStart.main(Native Method)
何を指示してるんですか?