リストメニューからタブホストアクティビティに移動するアプリケーションに取り組んでいます。
Menu.class -> Recharge.class Recharge.class は、prepaid.class という名前のタブを持つ TabActivity です。
以下のコードで、menu.class から prepaid.class に文字列を渡す必要があります。文字列を渡しました。コードのバグを見つけて助けてください。
Menu.class
if(s.equals("Recharge"))
{
Intent i = new Intent(menu.this,recharge.class);
i.putExtra("app",app);
startActivity(i);
}
リチャージクラス
Intent i = this.getIntent();
final String app=(String)i.getStringExtra("app");
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, prepaid.class);
intent.putExtra("app", app);
//Prepaid
spec = tabHost.newTabSpec("PREPAID").setIndicator("",
res.getDrawable(R.drawable.prepaid))
.setContent(intent);
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tabhost);
前払いクラス
Intent i=this.getIntent();
final String app=(String)i.getStringExtra("app");
これはログのエラーです:
09-10 14:37:44.038: E/AndroidRuntime(1172): FATAL EXCEPTION: main
09-10 14:37:44.038: E/AndroidRuntime(1172): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ezerecharge/com.example.ezerecharge.recharge}: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.ezerecharge/com.example.ezerecharge.prepaid}: java.lang.NullPointerException
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.os.Handler.dispatchMessage(Handler.java:99)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.os.Looper.loop(Looper.java:123)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-10 14:37:44.038: E/AndroidRuntime(1172): at java.lang.reflect.Method.invokeNative(Native Method)
09-10 14:37:44.038: E/AndroidRuntime(1172): at java.lang.reflect.Method.invoke(Method.java:507)
09-10 14:37:44.038: E/AndroidRuntime(1172): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-10 14:37:44.038: E/AndroidRuntime(1172): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-10 14:37:44.038: E/AndroidRuntime(1172): at dalvik.system.NativeStart.main(Native Method)
09-10 14:37:44.038: E/AndroidRuntime(1172): Caused by: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.ezerecharge/com.example.ezerecharge.prepaid}: java.lang.NullPointerException
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1487)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.widget.TabHost.setCurrentTab(TabHost.java:326)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.widget.TabHost.addTab(TabHost.java:216)
09-10 14:37:44.038: E/AndroidRuntime(1172): at com.example.ezerecharge.recharge.onCreate(recharge.java:33)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-10 14:37:44.038: E/AndroidRuntime(1172): ... 11 more
09-10 14:37:44.038: E/AndroidRuntime(1172): Caused by: java.lang.NullPointerException
09-10 14:37:44.038: E/AndroidRuntime(1172): at com.example.ezerecharge.prepaid.<init>(prepaid.java:22)
09-10 14:37:44.038: E/AndroidRuntime(1172): at java.lang.Class.newInstanceImpl(Native Method)
09-10 14:37:44.038: E/AndroidRuntime(1172): at java.lang.Class.newInstance(Class.java:1409)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-10 14:37:44.038: E/AndroidRuntime(1172): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)