Hiho!
Ich habe einen Fehler in meinem Code. Und zwar kann er an der Stelle "labelTV.setText(getString(R.string.tipps));" den String R.string.tipps nicht finden. In Strings.xml ist der String aber drin. Daher glaube ich, dass da ein Fehler mit dem Context ist und ich den falsch abrufe. Wo liegt mein Fehler?
Java
public class TabWidget extends TabActivity {
public TextView textview;
public JSONObject Jarr;
public ProgressDialog progDialog;
public LinearLayout ll;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TableLayout tl = new TableLayout(this);
final TableRow tr = new TableRow(this);
final TextView labelTV = new TextView(this);
final TextView labelTV2 = new TextView(this);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
ll = (LinearLayout) findViewById(R.id.ll1);
tl.setId(100);
tl.setStretchAllColumns(true);
tl.setBackgroundColor(Color.WHITE);
ll.addView(tl);
tr.setId(200);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
tl.addView(tr);
// Create a TextView to house the name of the province
labelTV.setId(200);
labelTV.setText(getString(R.string.tipps));
labelTV.setTextColor(Color.BLACK);
tr.addView(labelTV);
labelTV2.setId(201);
labelTV2.setText("2. Zelle");
labelTV2.setTextColor(Color.BLACK);
tr.addView(labelTV2);
textview =(TextView) findViewById(R.id.textView1);
textview.setText("This is the Artists tab");
return ll;
}
});
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
Alles anzeigen
Logcat Ausgabe:
Code
06-07 21:38:48.514: ERROR/AndroidRuntime(889): Uncaught handler: thread main exiting due to uncaught exception
06-07 21:38:48.533: ERROR/AndroidRuntime(889): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.sportwettenblogger.de.tabwidget/de.sportwettenblogger.de.tabwidget.TabWidget}: android.content.res.Resources$NotFoundException: String resource ID #0x7f040007
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.os.Looper.loop(Looper.java:123)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.ActivityThread.main(ActivityThread.java:4203)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at java.lang.reflect.Method.invoke(Method.java:521)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at dalvik.system.NativeStart.main(Native Method)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f040007
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.content.res.Resources.getText(Resources.java:205)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.content.res.Resources.getString(Resources.java:258)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.content.Context.getString(Context.java:149)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at de.sportwettenblogger.de.tabwidget.TabWidget$1.createTabContent(TabWidget.java:83)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.widget.TabHost$FactoryContentStrategy.getContentView(TabHost.java:600)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.widget.TabHost.setCurrentTab(TabHost.java:317)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.widget.TabHost.addTab(TabHost.java:210)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at de.sportwettenblogger.de.tabwidget.TabWidget.onCreate(TabWidget.java:96)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
06-07 21:38:48.533: ERROR/AndroidRuntime(889): ... 11 more
Alles anzeigen