【问题标题】:I'm trying to create a dynamic table but when i lunch the app it just crash我正在尝试创建一个动态表,但是当我午餐应用程序时它只是崩溃
【发布时间】:2019-03-17 23:43:30
【问题描述】:

表格代码

 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) 

【问题讨论】:

  • "这是我的错误:"

标签: java android


【解决方案1】:

看起来它告诉你它不知道可变资源 ID 是什么:

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

看了你发布的内容后的猜测

【讨论】:

猜你喜欢
  • 2017-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-23
  • 1970-01-01
  • 2015-04-18
  • 2017-05-22
相关资源
最近更新 更多