予有类似的问题像在下面的链接。!
I have similar problem like the one in the link below.!
passing链接和标题给android的一个web视图
我有这样的code。在MainActivity:
I have a code like this in the MainActivity:
ListView lv;
Arrayadapter<String>aa;
String items[]={"item1","item2"};
@Override
protected void onCreate(Bundle Savedinstancestate){
super.onCreate(Savedinstancestate);
lv=(ListView)findViewById(R.id.listView1);
aa=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_dropdown_item_1line,items) ;
lv.setAdapter(aa);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent newActivity0 = new Intent(MainActivity.this, Mywebpage.class);
newActivity0.putExtra("title", str[position]);
switch (position) {
case 0:
newActivity0.putExtra("url", "http://www.google.com");
break;
case 1:
newActivity0.putExtra("url", "file:///android_asset/item1.html");
break;
case 2:
newActivity0.putExtra("url", "file://android_asset/item2.html");
break;
}
和 MYPAGE
类得到的意图是像
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewpage);
Bundle extras = getIntent().getExtras();
String title, url;
if (extras != null) {
title = extras.getString("title");
url = extras.getString("url");
WebView wbView = (WebView) findViewById(R.id.WebView);
wbView.getSettings().setJavaScriptEnabled(true);
wbView.loadUrl(url);
// WbView.setWebViewClient(新myWebViewClient()); }
//WbView.setWebViewClient(new myWebViewClient()); }
和曾尝试与和没有设置的WebView客户(我曾评论对端线,有相应的类)。
And have tried with and without setting webview clients(the line which I have commented towards end, with a corresponding class).
我正在运行空指针异常,当我尝试点击该项目。
I am getting Runtime NULLPOINTER Exception when I try to click on the item.
我找到答案的问题!我宣布web视图,确定它的onCreate方法之前,在我的第二个活动,这导致了这个问题!
I found the answer to the problem! I had declared Webview, identifying it before onCreate method in my Second Activity, which has resulted in this problem.!
在code,它提供了previously,为putExtra也(字符串名称,值);
Also in the code, which had provided previously, as putExtra("stringname", "value");
所以,让群众演员后,在捆绑
And so, after getting extras, in Bundle
extras.getExtra(字符串名称);
extras.getExtra("stringname");
就足够了,并previously搞砸了在那个地方!
is enough and had previously messed up in that place.!
猜测,任何额外的logcat的信息,将进一步解决用于至少一个的问题有帮助。!因为它已经相当一段时间,在这之后我能得到的logcat的信息,由于一些问题,我曾在自己的!但感谢帮忙!本来upvoted所有! :-)
Guess, any additional logcat information would have helped further in resolving atleast one of the issues.! Since it had been quite sometime, after which I was able to get the logcat information due to a few issues, I worked on own.! But thanks for helping out.! Had upvoted all.! :-)