//. . .
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总是加载另一个HTMLMode。 SomeActivity加载someHTMLCode,除非mainActivityProcedure从MainActivity.onCreate调用。 someWebView或SomeActivity出了什么问题? 我不能把原始代码放在这里。
添加:loadDataWithBaseURL()中的Replacin` null无法修复它。 添加:Logcat显示消息java.lang.NullPointerException,它将Log.i()放入catch。
答案 0 :(得分:0)
试试这个,在MainActivity中启动SomeActivity并使用你可以访问的_someactivity对象。
SomeActivity _someactivity = new SomeActivity();
_someactivity.someActivityProcedure ();