ビューに4つの異なるクラスを使用していますが、4つのクラスのオブジェクトを1つのクラスに結合してから、ontouchlistenerを実装したいのですが、エラーが表示されます。私はそのエラーを理解していません。私のコードは次のとおりです。
public class AdActivity extends Activity {
DemoView demoview ;
DemoView2 finalview;
DemoView3 dview;
DemoView4 deview;
LowerView lview;
Finalview fview;
ViewFlipper c,d ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
demoview = new DemoView(this);
finalview = new DemoView2(this);
dview= new DemoView3(this);
deview = new DemoView4(this);
lview= new LowerView(this);
fview=new Finalview(this);
setContentView(fview);
}
public class Finalview extends View {
public Finalview(Context context) {
super(context);
// TODO Auto-generated constructor stub
c=(ViewFlipper)findViewById(R.id.viewFlipper2);
c.addView(demoview,0);
c.addView(finalview, 1);
c.addView(dview, 2);
c.addView(deview, 3);
c.setAutoStart(true);
c.setFlipInterval(1000);
c.startFlipping();
d=(ViewFlipper)findViewById(R.id.viewFlipper3);
d.addView(lview,0);
}
}
}
スタックトレースに次のエラーが表示されています。このエラーは発生しません。
05-07 15:28:56.900: E/AndroidRuntime(515): FATAL EXCEPTION: main
05-07 15:28:56.900: E/AndroidRuntime(515): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ad/com.example.ad.AdActivity}: java.lang.NullPointerException
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.os.Looper.loop(Looper.java:123)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-07 15:28:56.900: E/AndroidRuntime(515): at java.lang.reflect.Method.invokeNative(Native Method)
05-07 15:28:56.900: E/AndroidRuntime(515): at java.lang.reflect.Method.invoke(Method.java:521)
05-07 15:28:56.900: E/AndroidRuntime(515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-07 15:28:56.900: E/AndroidRuntime(515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-07 15:28:56.900: E/AndroidRuntime(515): at dalvik.system.NativeStart.main(Native Method)
05-07 15:28:56.900: E/AndroidRuntime(515): Caused by: java.lang.NullPointerException
05-07 15:28:56.900: E/AndroidRuntime(515): at com.example.ad.AdActivity$Finalview.<init>(AdActivity.java:420)
05-07 15:28:56.900: E/AndroidRuntime(515): at com.example.ad.AdActivity.onCreate(AdActivity.java:44)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-07 15:28:56.900: E/AndroidRuntime(515): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-07 15:28:56.900: E/AndroidRuntime(515): ... 11 more