2011-05-02 7 views
0

나는 제목 문자열안드로이드 텍스트 뷰와 널 포인터 예외

에게 있습니다

TextView bTitle = (TextView)findViewById(R.id.TextView); 

bTitle.setText(Html.fromHtml(title)); 

을하지만 난 두 번째 줄의 예에서 널 포인터 예외를 얻을. bTitle.setText (Html.fromHtml (title));

아무도 도와 드릴까요 ???

활동

public class NewsDetails extends ListActivity{ 

public static final String LOG_TAG = "Infra"; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.listplaceholder); 
    super.onStart(); 
    Intent myIntent = getIntent(); 
    String id = myIntent.getStringExtra("content_id"); 
    String title = myIntent.getStringExtra("title"); 
    //Spanned newTitle = Html.fromHtml(title); 
    //tv.setText(Html.fromHtml(title)); 
    TextView bTitle = (TextView)findViewById(R.id.TextView); 
    Log.d(LOG_TAG, "What is the value: " + bTitle); 
    bTitle.setText(Html.fromHtml(title)); 

    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); 


    String xml = XMLfunctions.getBodyXML(id); 
    String result = xml.replaceAll("<p>", "<p><div align=\"justify\">"); 
    String nXml = result.replaceAll("</p>", "</div></p>"); 
    TextView body = (TextView)findViewById(R.id.TextView1); 
    body.setText(Html.fromHtml(nXml)); 


    //Spanned body = Html.fromHtml(nXml); 
    /*HashMap<String, String> map = new HashMap<String, String>(); 
    map.put("title", tv.toString()); 
    map.put("news", tv1.toString()); 
    mylist.add(map);*/ 

    /*ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.list_item, new String[] { "title", "news" }, new int[] { R.id.item_title, R.id.item_subtitle }); 

    setListAdapter(adapter); 

    final ListView lv = getListView(); 
    lv.setTextFilterEnabled(true);*/ 
} 

레이아웃 - listplaceholder.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">  

    <ListView 
    android:id="@id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:drawSelectorOnTop="false" /> 

    <TextView 
     android:id="@id/android:empty" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="No data" 
     android:focusable="false" 
     android:clickable="true"/> 

</LinearLayout> 

text_view.xml

<LinearLayout android:id="@+id/LinearLayout01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

    <TextView 
     android:id="@+id/TextView" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:textSize="16px" 
     android:textStyle="bold"> 
    </TextView> 
    <TextView 
     android:id="@+id/TextView1" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:textSize="16px" 
     android:textStyle="bold"> 
    </TextView> 

</LinearLayout> 
+0

PLZ는 ... –

+0

@CapDroid 당신의 모든 코드 및 XML을 추가 : 내가보고 – ReNa

+0

지금까지 모든 운이하시기 바랍니다 코드를 추가 한? 우리가 더 많은 것을 도울 수 있도록 귀하의 우려 사항을 알려주십시오. 고맙습니다. – rekaszeru

답변

0

Intent myIntent = getIntent(); 
String id = myIntent.getStringExtra("content_id"); 
String title = myIntent.getStringExtra("title"); 

과 나 u는 목록에서 원하는 당신이 목록는, setAdapter를 호출 할 경우, 어디 어댑터가 무엇인지 알려주는 ... 당신의 도움에 대해 감사합니다. 내 응용 프로그램에서 많은 HTML 서식을 필요로하고 지금 내 텍스트가 적절한 형식으로 나타나고 또한 내 appliction 잘 실행중인 같이 textview webview로 바뀌 었습니다.

감사

+4

당신이 일하는 것을 관리 해준 그 위대한,하지만 이것은 당신의 질문에 대한 대답이 아닙니다. 참조한 레이아웃에없는보기에 액세스하려고 시도하여 NPE가 발생했습니다. – rekaszeru

1

M 실제로는

<TextView android:id="@+id/TextView [...] 

개를 활동의 레이아웃 xml에 포함시킬 수 있습니다. 당신의 listplaceholder.xml에서

업데이트
는 그런 TextView 없다!
레이아웃을 아이템 렌더러로 사용하는 경우 TextView에 액세스하려고 시도하는 코드는 ListAdapter 구현의 getView 메소드 안에 있어야합니다.

+0

내 코드를 공유 할 것입니다. 내가 해결책을 제시 할 수 없습니까? – ReNa

+0

[http://stackoverflow.com/questions/6196256/android-slider-effect-news-news-policy.asp?hl=ko에서 새 질문을 게시했습니다. 새로운 페이지로 이동]. 당신이 도울 수 있다면 매우 위대 할 것입니다. 감사합니다 – ReNa

0

1) 확인 R은

TextView bTitle = (TextView)findViewById(R.id.TextView); 

후 상단

2)에 가져 오기 (들) 섹션에서) android.R 네임 스페이스 프로젝트에서 수입 (및 있지 않은지 확인 수행합니다

을 (윈도우, 바로 로그 캣을 실행하는 경우, 리눅스를 사용하는 경우)

Log.d("debug", "bTitle: " + (bTitle != null)); 

및 터미널에서 체크 아웃 : 로그인

adb logcat | grep bTitle 

레이아웃에서 TextView를 제대로 가져 왔는지 알려야합니다 (예 : @rekaszeru 에서처럼 레이아웃에 TextView가있는 경우). 첫째

3) 제목 변수 당신은 내가 당신의 코드

1 개의 문제를 발견

setContentView(R.layout.text_view) 

TextView bTitle = (TextView)findViewById(R.id.TextView); 

bTitle.setText(Html.fromHtml(title)); 
2

로 null이 아닌 확인) 너의 TextView가 listplaceholder.xml에 없다. 그래서 널 포인터가 될거야.

2)이 코드를 추가해야 setContentView();

1

레이아웃에 대한 올바른 XML을로드해야 잘

관련 문제