这是我的代码:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
handler = new Handler();
FILENAME = getString(R.string.fileName);
if(!fileExistance(FILENAME)){
//create the file
FileOutputStream fos;
try {
fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
String string= "{'teamName':'name','players':[{'name':'mary','gol':'2','foto':'xxx','presence':'0'},{'name':'claudia','gol':'3','foto':'xxx','presence':'0'}]}";
fos.write(string.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//parsing dei dati dal file
String json = readFile();
team = parseJson(json);
appView.addJavascriptInterface(this, "MyTeam");
super.loadUrl("file:///android_asset/www/menu.html");
}
菜单.html:
<!DOCTYPE html>
<html>
<head>
<title>jQuery Mobile page</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="themes/myTheme.css" />
<link rel="stylesheet" href="themes/jquery.mobile.structure-1.2.0.css" />
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery.mobile-1.2.0.min.js"></script>
<script src="js/jquery-ui-1.9.1.custom.min.js"></script>
<script src="js/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript" src="js/jquery-chron.min.js"></script>
<!--script type="text/javascript" src="cordova-2.2.0.js"></script-->
<link rel="stylesheet" type="text/css" href="themes/jquery.mobile.simpledialog.min.css" />
<script type="text/javascript" src="js/jquery.mobile.simpledialog.min.js"></script>
<link rel="stylesheet" href="themes/main.css" />
</head>
<body onload="">
<div data-role="page" data-theme="a">
<div data-role="header" data-position="inline">
<img style="float:left;width:41px;" src="themes/images/ball.png"/>
<img style="float:right;width:41px;" src="themes/images/ball.png"/>
<div style="text-align:center"><h1 style="font-size: 1.1em;">Futsal Manager 1.0!</h1></div>
<div id="navbar" style="display:none" data-role="navbar" data-iconpos="top">
<ul>
<li><a href="#" data-icon="refresh" >Substitutions</a></li>
<li><a href="#" data-icon="star" >Gol</a></li>
</ul>
</div><!-- /navbar -->
</div>
<div data-role="content" data-theme="a" id="content">
<a data-role="button" data-transition="none" style="margin: 2em;" id="newGame">New Match</a>
<a data-role="button" data-transition="none" style="margin: 2em;" id="ranking">Players gol/presence</a>
<a data-role="button" data-transition="none" style="margin: 2em;" id="settings">Settings</a>
<p id="info"></p>
</div>
<div data-role="footer" style="text-align:center">
<p class="pFooter">Developed by</p>
<img style="text-align:center" src="themes/images/logo.png" />
<p class="pFooter">http://www.michelepierri.it</p>
</div>
</div>
</body>
</html>
问题是该页面已正确加载,但是当我单击按钮时出现此异常:12-01 14:45:57.972: E/AndroidRuntime(11229): android.view.ViewRoot$CalledFromWrongThreadException: 只有原始线程创建了一个视图层次结构可以触摸它的视图。
但它适用于 Android 4.0 和最新版本,但从 Android 2.3 到 3 应用程序崩溃。
谁能帮我?非常感谢。