2010-12-28 7 views
4

오케이, 세 번째 작업을 시작할 때 널 포인터 예외가 발생합니다. 내가 활동 호출 할 경우 다음 새 작업을 시작할 때 널 포인터 예외가 발생합니다.

 
12-28 04:38:00.350: ERROR/AndroidRuntime(776): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acithium.main/com.acithium.rss.ShowDescription}: java.lang.NullPointerException 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.ActivityThread.access$2100(ActivityThread.java:116) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.os.Looper.loop(Looper.java:123) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.ActivityThread.main(ActivityThread.java:4203) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at java.lang.reflect.Method.invoke(Method.java:521) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at dalvik.system.NativeStart.main(Native Method) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776): Caused by: java.lang.NullPointerException 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at com.acithium.rss.ShowDescription.onCreate(ShowDescription.java:48) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
12-28 04:38:00.350: ERROR/AndroidRuntime(776):  ... 11 more 

코드의 섹션 : 여기

public void onItemClick(AdapterView parent, View v, int position, long id) 
{ 
    Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]"); 

    Intent itemintent = new Intent(this,com.acithium.rss.ShowDescription.class); 
    //Intent itemintent = new Intent(); 
    //itemintent.setClassName("com.acithium.main", "com.acithium.rss.ShowDescription"); 
    Bundle b = new Bundle(); 
    b.putString("title", feed.getItem(position).getTitle()); 
    b.putString("description", feed.getItem(position).getDescription()); 
    b.putString("link", feed.getItem(position).getLink()); 
    itemintent.putExtra("android.intent.extra.INTENT", b); 

    startActivityForResult(itemintent,0); 
} 

그리고라고 새로운 활동 클래스입니다 : 여기

public class ShowDescription extends Activity 
{ 

    public void onCreate(Bundle icicle) 
    { 
     super.onCreate(icicle); 
     setContentView(R.layout.showdescription); 

     String theStory = null; 


     Intent startingIntent = getIntent(); 


     if (startingIntent != null) 
     { 
      Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT"); 
      if (b == null) 
      { 
       theStory = "bad bundle?"; 
      } 
      else 
      { 
       theStory = b.getString("title") + "\n\n" + b.getString("description") + "\n\nMore information:\n" + b.getString("link"); 
      } 
     } 
     else 
     { 
      theStory = "Information Not Found."; 

     } 
     TextView db= (TextView) findViewById(R.id.storybox); 
     db.setText(theStory); 

     Button backbutton = (Button) findViewById(R.id.back); 

     backbutton.setOnClickListener(new Button.OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       finish(); 
      } 
     });   
    } 
} 

여기에 로그 캣 메시지는 showdescription.xml 파일입니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <ScrollView android:layout_width="fill_parent" 
      android:layout_height="fill_parent" > 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
     <TextView 
      android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:autoLink="all" 
       android:text="story goes here ...." 
      android:id="@+id/storybox" /> 
     <Button 
       android:layout_height="wrap_content" 
       android:text="Back" 
      android:id="@+id/back" 
      android:layout_width="100px" 
      android:layout_marginLeft="100px"/> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
+0

글쎄, 나는 해결책을 찾았습니다. 처음에는이 클래스들을 별도의 패키지에 넣었지만 모두 동일한 패키지로 옮기고 그 패키지와 관련된 사용되지 않은 R 파일을 삭제했습니다. 일단 내가 그 일을하기 시작했다. 나는 그것을 "해결 된 것"이라고 부르지 않을 것입니다. – acithium

+0

아! 그것은 그것을 설명한다! 그것이 다른 패키지에 있다면, 당신이 참조하는 "R"은 당신이 필요로하는 R이 아니게됩니다! 옳지 않을 수도있는 제 2의 생각에 ... 그것은 컴파일에 실패했을 것입니다. –

+0

그래, 나는 그것도 얻지 않는다. 그들이 2 초짜리 패키지에있을 때, 나는 R 파일을위한 import 문을 추가했지만, 여전히 널 포인터를 얻고 있었다. 나는 지금 당장이 방법을 떠날 것 같다. 감사합니다 – acithium

답변

2

이것은 스택 추적에서 얻은 단서입니다.

12-28 03:47:21.670: ERROR/AndroidRuntime(862): Caused by: java.lang.NullPointerException 
12-28 03:47:21.670: ERROR/AndroidRuntime(862): at com.acithium.rss.ShowDescription.onCreate(ShowDescription.java:47) 

ShowDescription.java의 줄 47은 무엇입니까?

+0

// line 47은이 두 라인 사이의 공백 라인입니다. db.setText (theStory); // 빈 줄 단추 뒤로 단추 = (단추) findViewById (R.id.back); – acithium

+0

acithium : 그건 말이되지 않습니다. 오류가 발생하면 소스를 편집 했어야합니다. 다시 빌드하고 다시 실행하여 정확히 어떤 줄이 있는지 알려줄 수 있습니다. –

+0

좋습니다. 이제 db.setText (theStory); 문제를 일으키는 선입니다. – acithium

0

ShowDescription 코드의 47 행은 무엇입니까? 나는 당신이 null 커서를 전달하고 있다고 생각합니다.

+0

나는 새로운 logcat을 올렸습니다.이 로그는 현재 48 행에 있음을 보여줍니다. 해당 코드 줄은 다음과 같습니다. db.setText (theStory); – acithium

1

코드를 제대로 이해했다면 button 및 textview가 모두 해당보기의 일부인 것처럼 보이기 때문에 활동이 아닌 활동에 대해 설정 한 showdescription보기의 findViewById()를 호출해야합니다.

super.onCreate(icicle); 
View showdescription = this.findViewById(R.id.showdescription); 
setContentView(showdescription); 

// .. 

TextView db = (TextView)showdescription.findViewById(R.id.storybox); 
db.setText(theStory); 

Button backbutton = (Button)showdescription.findViewById(R.id.back); 
backbutton.setOnClickListener(new Button.OnClickListener() 
{ 
    public void onClick(View v) 
    { 
     finish(); 
    } 
}); 
관련 문제