說我有一個字符串,我已格式化爲包含粗體字母。但在某些時候,我需要能夠去除格式。下面是我已經試過,但繼續得到NullPointerException異常Html.fromHtml不斷拋出NullPointerException
這裏是我的方法
public String stripFormatting(String input){
return Html.fromHtml(input).toString();
}
下面是一個電話
stripFormatting("<b>0</b>")
的錯誤跟蹤不必多說了,但在這裏
java.lang.NullPointerException
at com.mypkg.utils.MyClassTest.stripFormatting(MyClassTest.java:111)
at com.mypkg.utils.MyClassTest.testLessThan100_000(MyClassTest.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
我照你的建議做了。從android studio中,我將目錄移動到'(androidTest)'的子目錄。但現在它說:「未找到類...空測試套件」。 –
您可能需要在類聲明之上使用'@RunWith(AndroidJUnit4.class)'註釋測試類(即,在public class ... Test {'以告訴Android Studio它是一個儀器測試。您可以找到更多信息在這裏:https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html – JRod
我沒有運氣,我一直在看官方文檔和所有堆棧溢出。一直說「找不到類:」mypackage.MyClass「空測試套件」 –