安卓 2.3.3
我有一个表,其中有 12 列和任意数量的行。我是第一次使用 TableLayout。我看过几个例子并写了一个代码(不多)。只是为了动态填充一行 12 列。但是我遇到了一个例外..这是详细信息..
例外 :::
02-11 21:57:21.569: E/AndroidRuntime(465): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxx/com.xx.xxx.Portfolio}: android.content.res.Resources$NotFoundException: Resource ID #0x7f070037 type #0x12 is not valid
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.os.Handler.dispatchMessage(Handler.java:99)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.os.Looper.loop(Looper.java:123)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-11 21:57:21.569: E/AndroidRuntime(465): at java.lang.reflect.Method.invokeNative(Native Method)
02-11 21:57:21.569: E/AndroidRuntime(465): at java.lang.reflect.Method.invoke(Method.java:507)
02-11 21:57:21.569: E/AndroidRuntime(465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-11 21:57:21.569: E/AndroidRuntime(465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-11 21:57:21.569: E/AndroidRuntime(465): at dalvik.system.NativeStart.main(Native Method)
02-11 21:57:21.569: E/AndroidRuntime(465): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070037 type #0x12 is not valid
02-11 21:57:21.569: E/AndroidRuntime(465): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.content.res.Resources.getLayout(Resources.java:731)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-11 21:57:21.569: E/AndroidRuntime(465): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.Activity.setContentView(Activity.java:1657)
02-11 21:57:21.569: E/AndroidRuntime(465): at com.xx.xxx.Portfolio.dummy(Portfolio.java:47)
02-11 21:57:21.569: E/AndroidRuntime(465): at com.xx.xxx.Portfolio.onCreate(Portfolio.java:28)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-11 21:57:21.569: E/AndroidRuntime(465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-11 21:57:21.569: E/AndroidRuntime(465): ... 11 more
活动 :::
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TableLayout
android:id="@+id/tableLayoutPorfolio"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Java 文件 :::
import android.app.Activity;
import android.os.Bundle;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class Portfolio extends Activity{
TableLayout tblPorfolio;
TableRow trScript;
TextView txtV;
String[] dummy = {"1","12345","XYZABC","10000","10000","10000","10000","10000","10000","10000","10000","10000","10000"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_portfolio);
tblPorfolio = (TableLayout) findViewById(R.id.tableLayoutPorfolio);
trScript = new TableRow(this);
dummy();
}
private void dummy() {
// TODO Auto-generated method stub
int i = 0;
txtV = new TextView(this);
while(i < dummy.length)
{
txtV.setText(dummy[i]);
trScript.addView(txtV);
i++;
}
tblPorfolio.addView(trScript);
setContentView(R.id.tableLayoutPorfolio);
}
}
我必须在一行中显示 12 列和一些 N 行。所有这些值都将从数据库中检索并填充。
有人可以告诉我,我做错了什么(如果我一开始做对了)?