程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-在eclipse裡的Android程序為什麼一運行就停止運行了?(新人求教)

android-在eclipse裡的Android程序為什麼一運行就停止運行了?(新人求教)

編輯:編程綜合問答
在eclipse裡的Android程序為什麼一運行就停止運行了?(新人求教)

package com.android.mytextview;

import java.lang.reflect.Field;

import android.support.v7.app.ActionBarActivity;
import android.text.Html;
import android.text.Html.ImageGetter;
import android.text.method.LinkMovementMethod;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

public int getResourceId(String name) {
    try {
        Field feild = R.drawable.class.getField(name);
        return Integer.parseInt(feild.get(null).toString());
    } catch (Exception e) {
        // TODO: handle exception
    }

    return 0;

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textView = (TextView) this.findViewById(R.id.textview3);
    textView.setTextColor(Color.BLACK);
    textView.setBackgroundColor(Color.WHITE);
    textView.setTextSize(20);
    String html = "艾斯<img src='image(1)'/>海賊<img src='image(2)'/>哆啦A夢<img src='image(3)'/><p>";
    html += "傳送門<a href='http://baidu.com'><img src='image(6)'></a>功夫熊貓<img src='image(4)'/>";

    CharSequence charSequence = Html.fromHtml(html, new ImageGetter() {

        @Override
        public Drawable getDrawable(String source) {
            // TODO 自動生成的方法存根
            Drawable drawable = getResources().getDrawable(
                    getResourceId(source));
            if (source.equals("image(3)")) {
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth() / 2,
                        drawable.getIntrinsicHeight() / 2);
            } else {
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                        drawable.getIntrinsicHeight());
            }
            return drawable;
        }
    }, null);
    textView.setText(charSequence);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

}

這是錯誤日志
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (1).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (1).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (1).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (2).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (2).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (2).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (3).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (3).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (3).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (4).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (4).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (4).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (6).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (6).png: Invalid file name: must contain only [a-z0-9_.]
[2015-12-18 20:13:37 - android_textview1] res\drawable-hdpi-v4\image (6).png: Invalid file name: must contain only [a-z0-9_.]

最佳回答:


android_textview1] res\drawable-hdpi-v4\image (1).png: Invalid file name: must contain only [a-z0-9_.],說明你的文件命名有問題,去掉()

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved