我已经工作了几天,将数据数组显示到TextView数组中。我想要最多10行TextViews 4列。
目前我有以下.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)上输入债务信息,该信息意图选择“添加”按钮。意图将把他的活动数据显示在ADDITION中以显示旧数据。
答案 0 :(得分:2)
答案 1 :(得分:0)
我没有看到你的import语句,但你可能错了。
您可以拥有导入... ViewGroup.LayoutParams (或LinearLayout.LayoutParams) 导入ActionBar.LayoutParams ,它不适用于pre API 11(这是错误的, 因为ActionBar.LayoutParams与LinearLayout.LayoutParams不兼容)。通过改变它 你应该使用任何API,甚至API 1!
P.S要更改目标API,请转到Project / Properties / Android并选择目标,前提是您已安装相应的API。