TextView textView1 = (TextView) getActivity().findViewById(R.id.date);
String s1 = textView1.getText().toString();
,但在第二行落在错误:
java.lang.NullPointerException
at com.ancort.cryptophone.guitest.CAMyTest.testMail_000(CAMyTest.java:94)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:177)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)
而且,我试图
TextView textView1 = (TextView)findViewByID(R.id.date);
String s = textView1.getText().toString();
但在这种情况下, “findViewByID” 错误红色亮点”无法解析findViewById(int)方法“。我知道类必须从Activity类继承,但是我的类从另一个类继承而来。如何获得textview的价值?
你把这段代码放在setContentView之前吗? – 2014-11-25 11:37:07
显示您的xml代码布局 – Suvitruf 2014-11-25 11:37:10
请发布您的完整代码。 – 2014-11-25 11:37:11