我已经工作了几天,将数据数组显示到 TextView 数组中。最好我想要最多 10 行 4 列的 TextViews。
目前我有以下 .java 文件,它正在引发一个致命错误:
public class DebtList extends Activity {
Integer trigger = 5;
Double totalDebt = 0.00;
//TextView dispTotalDebt = (TextView)findViewById(R.id.dispTotalDebt);
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.debtlist);
Bundle extras = getIntent().getExtras();
String[] debtNames = new String[10];
Double[] debtAmount = new Double[10];
Double[] debtRate = new Double[10];
Double[] debtTerm = new Double[10];
debtNames[trigger] = extras.getString("nickname");
View linearLayout = findViewById(R.id.debtlist);
Integer stopper = trigger+1;
for(int i=0; i < stopper; i++)
{
TextView value = new TextView(this);
value.setText("test" + i); //debtNames[i] later
value.setId(i);
value.setTextSize(50);
value.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
((LinearLayout) linearLayout).addView(value);
}
trigger++;
}
}
这是.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/debtlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/totalDebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total Debt:" />
<TextView
android:id="@+id/dispTotalDebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
最后,这是我运行它时的 logcat。
10-13 02:16:16.785: W/dalvikvm(898): threadid=1: thread exiting with uncaught exception (group=0x40015560)
10-13 02:16:16.795: E/AndroidRuntime(898): FATAL EXCEPTION: main
10-13 02:16:16.795: E/AndroidRuntime(898): java.lang.NoClassDefFoundError: android.app.ActionBar$LayoutParams
10-13 02:16:16.795: E/AndroidRuntime(898): at biz.midl.debttracking.DebtList.onCreate(DebtList.java:42)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.os.Looper.loop(Looper.java:123)
10-13 02:16:16.795: E/AndroidRuntime(898): at android.app.ActivityThread.main(ActivityThread.java:3683)
10-13 02:16:16.795: E/AndroidRuntime(898): at java.lang.reflect.Method.invokeNative(Native Method)
10-13 02:16:16.795: E/AndroidRuntime(898): at java.lang.reflect.Method.invoke(Method.java:507)
10-13 02:16:16.795: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-13 02:16:16.795: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-13 02:16:16.795: E/AndroidRuntime(898): at dalvik.system.NativeStart.main(Native Method)
最终结果,我希望一个人能够在 Activity (DebtInput.java) 上输入债务信息,该信息旨在选择“添加”按钮。意图将把数据带到他的活动中,以便在旧数据的补充中显示。