在源代碼中使用一對{{#......}} {{/ .......}}來顯示/隱藏,然後一切正常;加入只是多了一個對(顯示/隱藏)時,它給我一個錯誤:不隱藏在小鬍子模板語言中顯示幾個字段
九月3日至11日:53:33.847:WARN/dalvikvm(13459):線程ID = 1:螺紋與未捕獲的異常退出(組= 0x2aacc8a0) 03-11 09:53:33.917:錯誤/ AndroidRuntime(13459):致命異常:主要 java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example/com.example.MyActivity}: com .samskivert.mustache.MustacheParseException:Section丟失關閉標記'dic'@ line 47 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2705) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2721) 在android.app.ActivityThread.access $ 2300(ActivityTh read.java:132) at android.app.ActivityThread $ h.handleMessage(ActivityThread.java:2071) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop( (java.lang.reflect.Method.invokeNative(Native Method)) at java.lang.reflect.Method.invoke(Method()方法)的.java:521) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:876) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634) 在達爾維克.system.NativeStart.main(本地方法) 引起:com.samskivert.mustache.MustacheParseException:部分丟失關閉標記'dic'@ line 47 at com.samskivert.mustache.Mustache $ Accumulator $ 1.finish(Mustache.java:433) at com.samskivert.mustache.Mustache.compile(Mustache.java:167) at com.samskivert.mustache.Mustache $ Compiler .compile(Mustache.java:61) 在com.samskivert.mustache.Mustache $ Compiler.compile(Mustache.java:56) 在com.example.MyActivity.onCreate(MyActivity.java:130) 在android.app .Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669) ... 11 more 03-11 09:53:34.007:WARN/ActivityManager(179):強制整理活動com.example/.MyActivity 03-11 09:53:34.007:WARN/WindowManager(179):updateFocusedWindowLocked newFocus = null mode = 0 mCurrentFocus = null 03-11 09:53:34.047:WARN/WindowManager(179):updateFocusedWindowLocked newFocus = Window {300fb6b8 application Error!暫停= false} mode = 1 mCurrentFocus = null 03-11 09:53:34.057:WARN/WindowManager(179):updateFocusedWindowLocked newFocus = Window {300fb6b8Ошибкаприложения! paused = false} mode = 3 mCurrentFocus =窗口{300fb6b8應用程序錯誤! paused = false} 03-11 09:53:34。057:調試/ KeyguardViewMediator(179):setHidden假
的代碼行,錯誤:
Template tmpl = Mustache.compiler().escapeHTML(false).compile(template);
程序代碼:
public class MyActivity extends Activity
{
private final static String LOG = "WedView";
String template;
String value = "";
Boolean True = true;
Boolean False = false;
WebView mWebView;
private class ContosoWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) throws MustacheException
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Tg tg = new Tg(new Date(), "5345", "ghfg", 4455, 0.0, 0);
Tzzz tzzz = new Tzzz(2, "", "", "", "",
"gdfg", "fgdfgdf", "", "", "gdfgdg", "gfdf", "fgd1", 36.6, 121, "Joe ", "555-5555", "", "",
true, false, 208.9, new Date(41, 12, 12, 13, 30),
"hhh", "12345678", "2zzzz", "21", "", "", "", "", "", "");
tg.Stops.add(tzzz);
try
{
InputStream is = getAssets().open("DetailActivity.htm");
template = new ReadFile().Read(is);
}
catch (IOException e)
{
Log.d(LOG, " error", e);
}
DecimalFormat f = new DecimalFormat("##.0");
Template tmpl = Mustache.compiler().escapeHTML(false).compile(template);
Map<String, Object> data = new HashMap<String, Object>();
........................
value = tzzz.Value1;
data.put("tv_stopH", value);
value = tzzz.Value2;
data.put("tv_sch", value);
value = tzzz.Value3;
data.put("arri", value);
value = tzzz.Value4;
data.put("tv_add", value);
value = tzzz.Value5;
data.put("cont", value);
value = tzzz.Value6;
data.put("tv_cont", value);
if(tripStop.RefName1.length() > 0)
{
data.put("pic1", True);
value = tzzz.Value7;
data.put("tv_refName1", value);
value = tzzz.Value8;
data.put("tv_ref1", value);
}
if(tripStop.Ref1.length() > 0)
{
data.put("dic", True);
value = tzzz.Value9;
data.put("tv_refName2", value);
value = tzzz.Value10;
data.put("tv_ref2", value);
}
......................
try
{
File file = new File("sdcard/Android/data/com.aplication/files/main.css");
boolean success = file.createNewFile();
BufferedWriter outfile = new BufferedWriter(new FileWriter("sdcard/Android/data/com.aplication/files/main.css"));
outfile.write(Css_file);
outfile.close();
}
catch (IOException e)
{
Log.d(LOG, " error!", e);
}
String temp = tmpl.execute(data);
mWebView = (WebView) this.findViewById(R.id.webView);
// Disable scrollbars
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
// Scrollbar Overlay Content
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAppCacheEnabled(false);
mWebView.addJavascriptInterface(new MyJavaScriptInterface(this), "AndroidFunction");
mWebView.loadDataWithBaseURL(null, temp, "text/html", "utf-8", null);
mWebView.setWebViewClient(new ContosoWebViewClient());
}
HTML代碼:
<div class="section3">
<span class="section3_label1">{{tv_stopH}}</span><span class="section3_label2"> {{tv_sch}}</span>
</div>
<div class="section3_1">
<div class="section3_1_textblock1">
<span class="label_alt">{{arri}}</span><br />
{{tv_add}}
</div>
<div class="section3_1_textblock2">
<span class="label_alt">{{cont}}</span><br />
{{tv_cont}}
</div>
<div class="section3_1_textblock1">
{{#pic1}}
<span class="label_alt">{{tv_refName1}}:</span> {{tv_ref1}}<br />
{{/pic1}}
{{#dic}}
<span class="label_alt">{{tv_refName2}}:</span> {{tv_ref2}}<br />
{{/dic}}
</div>
改變了它。不過,同樣的錯誤出現。 – zesen 2012-03-11 15:05:01