模拟器开启错误

报错内容见截图。在手机上运行没问题。
package com.david.html;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.david.domain.Contact;
import com.david.service.ContactService;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;

public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
private WebView webView;
private ContactService service;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
service = new ContactService();
webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);//打开脚本功能
webView.addJavascriptInterface(new ContactPlugin(), "david");//创建js插件
// webView.loadUrl("file:///android_asset/index.html");//加载给定路径的web
webView.loadUrl("http://192.168.101.160:8080/videoWeb/index.html");
}
/**
* 定义js插件
* @author davidhuang
*
*/
private class ContactPlugin
{
public void getContacts() {
List contacts = service.getContacts();//获取联系人数据
try {
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < contacts.size(); i++) {
Contact contact = contacts.get(i);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", contact.getId());
jsonObject.put("name", contact.getName().toString());
jsonObject.put("mobile", contact.getMobile());
jsonArray.put(jsonObject);
}
String jsonString = jsonArray.toString();//转换为json字符串
System.out.println(jsonString);
webView.loadUrl("javascript:show('"+jsonString+"')");
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}

public void call(String mobile)
{
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:" + mobile));
startActivity(intent);
}
}
}

你可能感兴趣的:(模拟器开启错误)