//. . .
public class MainActivity extends Activity {
//. . .
@Override
protected void onCreate( Bundle savedInstanceState ) {
//. . .
mainActivityProcedure ( );
}
//. . .
public static void mainActivityProcedure ( ) {
//. . .
AnotherActivity.anotherActivityProcedure ( ) ;
SomeActivity.someActivityProcedure ( );
//. . .
}
//. . .
}
//. . .
public class SomeActivity extends Activity {
//. . .
@Override
protected void onCreate( Bundle savedInstanceState ) {
//. . .
someWebView = ( WebView ) findViewById ( R.id.someWebView );
//. . .
}
//. . .
public static void someActivityProcedure ( ) {
//. . .
try {
someWebView.loadDataWithBaseURL ( null , someHTMLCode, mimeType, encoding, null );
catch ( Exception e ) {
Log.i("SomeActivity", "someWebView loadDataBaseURL () " + e.toString() );
}
//. . .
}
//. . .
}
//. . .
public class AnotherActivity extends Activity {
//. . .
@Override
protected void onCreate ( Bundle savedInstanceState ) {
//. . .
anotherWebView = ( WebView ) findViewById ( R . id.anotherWebView ) ;
//. . .
}
//. . .
public static void anotherActivityProcedure ( ) {
//. . .
anotherWebView . loadDataWithBaseURL ( null, anotherHTMLCode, mimeType, encoding, null ) ;
//. . .
}
}
当 anotherActivityProcedure 调用时,AnotherActivity 总是加载 anotherHTMLCode。 SomeActivity 加载 someHTMLCode,除非 mainActivityProcedure 从 MainActivity.onCreate 调用。 someWebView 或 SomeActivity 有什么问题? 我不能在这里放置原始代码。
添加:loadDataWithBaseURL() 中的 Replacin` null 无法修复它。 添加:Logcat 显示消息 java.lang.NullPointerException,该消息将 Log.i() 从 catch 中取出。
最佳答案
试试这个,在 MainActivity 中初始化 SomeActivity 并使用您可以访问的 _someactivity 对象。
SomeActivity _someactivity = new SomeActivity();
_someactivity.someActivityProcedure ();
关于java - WebView loadDataWithbaseURL java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331298/