我正在尝试创建动态表,但是当我在应用程序中吃午餐时,它崩溃了

时间:2018-10-12 17:46:56

标签: java android

表格代码

 public class Main5Activity extends AppCompatActivity {

    @Override
     protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main5);

    {
        TableLayout markstable = (TableLayout) findViewById(R.id.datatable);
        TableRow tableRow = new TableRow(this);
        TextView tv0 = new TextView(this);
        tv0.setText(" Student ");
        tv0.setTextColor(Color.WHITE);
        tableRow.addView(tv0);
        TextView tv1 = new TextView(this);
        tv1.setText(" Oral Mark ");
        tv1.setTextColor(Color.WHITE);
        tableRow.addView(tv1);
        TextView tv2 = new TextView(this);
        tv2.setText(" Home Work ");
        tv2.setTextColor(Color.WHITE);
        tableRow.addView(tv2);
        TextView tv3 = new TextView(this);
        tv3.setText(" Test ");
        tv3.setTextColor(Color.WHITE);
        tableRow.addView(tv3);
        markstable.addView(tableRow);
        for (int i = 0; i < 50; i++) {
            TableRow tableRow1 = new TableRow(this);
            TextView t1v = new TextView(this);
            t1v.setText( + i);
            t1v.setTextColor(Color.WHITE);
            t1v.setGravity(Gravity.CENTER);
            tableRow1.addView(t1v);
            TextView t2v = new TextView(this);
            t2v.setText("Student " + i);
            t2v.setTextColor(Color.WHITE);
            t2v.setGravity(Gravity.CENTER);
            tableRow1.addView(t2v);
            TextView t3v = new TextView(this);
            t3v.setText("Student" + i);
            t3v.setTextColor(Color.WHITE);
            t3v.setGravity(Gravity.CENTER);
            tableRow1.addView(t3v);
            TextView t4v = new TextView(this);
            t4v.setText( + i * 15 / 32 * 10);
            t4v.setTextColor(Color.WHITE);
            t4v.setGravity(Gravity.CENTER);
            tableRow1.addView(t4v);
            markstable.addView(tableRow1);

                     }

              }
           }
       }

在这里,我尝试为老师制作一张桌子,以在其中保存学生的姓名和标记,并保存以对其进行编辑,删除或替换 桌子崩溃了 顺便说一句,我试图使他们成为一个文本字段来输入数据,但它也崩溃 这是我的错误:

Process: com.mohnad.theeducationnewera.marksbook, PID: 4321
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mohnad.theeducationnewera.marksbook/com.mohnad.theeducationnewera.marksbook.Main5Activity}: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
        at android.content.res.Resources.getText(Resources.java:274)
        at android.widget.TextView.setText(TextView.java:4122)
        at com.mohnad.theeducationnewera.marksbook.Main5Activity.onCreate(Main5Activity.java:45)
        at android.app.Activity.performCreate(Activity.java:5933)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 
        at android.app.ActivityThread.access$800(ActivityThread.java:144) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5221) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 

1 个答案:

答案 0 :(得分:0)

它似乎告诉您它不知道变量资源ID是什么:

原因:android.content.res.Resources $ NotFoundException:字符串资源ID#0x0

看看您发布的内容只是一个猜测