2013-06-04 2 views
0

제발 좀 도와주세요. 여기에 미안 코드와 logcat 드롭, 나는 당신이 나를 보여줄 수 있기를 바랍니다.프래그먼트 대화 내부 조각 내 활동

더 나은 이해를 위해, 내가 찾고있는 것은; 액티비티 "concejos"에는 스 와이프 탭이 있고, 각 탭은 조각과 같은 레이아웃입니다. 레이아웃 안에는 이미지, 텍스트 및 닫기 버튼이있는 대화 상자 조각이 열리는 버튼이 있습니다.

CODE

public class Concejos extends FragmentActivity implements ActionBar.TabListener { 

AppSectionsPagerAdapter mAppSectionsPagerAdapter; 
ViewPager mViewPager; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_concejos); 

    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager()); 

    final ActionBar actionBar = getActionBar(); 
    actionBar.setHomeButtonEnabled(false); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

    mViewPager = (ViewPager) findViewById(R.id.pager); 
    mViewPager.setAdapter(mAppSectionsPagerAdapter); 
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 
     @Override 
     public void onPageSelected(int position) { 
      // When swiping between different app sections, select the corresponding tab. 
      // We can also use ActionBar.Tab#select() to do this if we have a reference to the 
      // Tab. 
      actionBar.setSelectedNavigationItem(position); 
     } 
    }); 

    // For each of the sections in the app, add a tab to the action bar. 
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) { 
     actionBar.addTab(
       actionBar.newTab() 
         .setText(mAppSectionsPagerAdapter.getPageTitle(i)) 
         .setTabListener(this)); 
    } 
} 
@Override 
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { 
} 

@Override 
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { 
    mViewPager.setCurrentItem(tab.getPosition()); 
} 

@Override 
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { 
} 

public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { 
    public AppSectionsPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 
    @Override 
    public Fragment getItem(int position) { 
     switch (position) { 
      case 0: 
       return new SectionFragmentCocina(); 
      case 1: 
       return new SectionFragmentComedor(); 
      case 2: 
       return new SectionFragmentCuartoLavado(); 
      case 3: 
       return new SectionFragmentBano(); 
      default: 
       return new SectionFragmentCocina(); 
     } 
    } 

    @Override 
    public int getCount() { 
     return 4; 
    } 
    @Override 
    public CharSequence getPageTitle(int position) { 
     switch (position) { 
     case 0: 
      return "Cocina"; 
     case 1: 
      return "Comedor"; 
     case 2: 
      return "Cuarto de lavado"; 
     case 3: 
      return "Baño"; 
     } 
     return null; 
    } 
} 


public static class SectionFragmentCocina extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_cocina, container, false); 
     // Demonstration of a collection-browsing activity. 
     rootView.findViewById(R.id.btnLavavajilla).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Context context = null; 
       /*Intent intent = new Intent(getActivity(), SectionFragment1.class); 
       startActivity(intent);*/ 
       final Dialog dialog = new Dialog(context); 
       dialog.setContentView(R.layout.fragment_dialog); 
       dialog.setTitle("Title..."); 

       // set the custom dialog components - text, image and button 
       TextView text = (TextView) dialog.findViewById(R.id.txtTexto); 
       text.setText("Android custom dialog example!"); 
       ImageView image = (ImageView) dialog.findViewById(R.id.ivImagen); 
       image.setImageResource(R.drawable.ic_launcher); 

       Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK); 
       // if button is clicked, close the custom dialog 
       dialogButton.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         dialog.dismiss(); 
        } 
       }); 

       dialog.show(); 
      } 
     }); 
     return rootView; 
    } 
} 


public static class SectionFragmentComedor extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_comedor, container, false); 
     // Demonstration of a collection-browsing activity. 
     /*rootView.findViewById(R.id.btnLavavajilla).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent intent = new Intent(getActivity(), SectionFragment2.class); 
       startActivity(intent); 
      } 
     });*/ 
     return rootView; 
    } 
} 

public static class SectionFragmentCuartoLavado extends Fragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_cuarto_lavado, container, false); 
     // Demonstration of a collection-browsing activity. 
     /*rootView.findViewById(R.id.btnLavavajilla).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent intent = new Intent(getActivity(), SectionFragment3.class); 
       startActivity(intent); 
      } 
     });*/ 
     return rootView; 
    } 
} 

public static class SectionFragmentBano extends Fragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_bano, container, false); 
     // Demonstration of a collection-browsing activity. 
     /*rootView.findViewById(R.id.btnLavavajilla).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent intent = new Intent(getActivity(), SectionFragment4.class); 
       startActivity(intent); 
      } 
     });*/ 
     return rootView; 
    } 
} 

}

로그 캣

06-04 10:05:59.111: D/dalvikvm(560): GC_FOR_ALLOC freed 99K, 3% free 6972K/7171K, paused 133ms 
06-04 10:05:59.151: I/dalvikvm-heap(560): Grow heap (frag case) to 8.370MB for 1536016-byte allocation 
06-04 10:05:59.331: D/dalvikvm(560): GC_CONCURRENT freed 1K, 3% free 8471K/8711K, paused 9ms+35ms 
06-04 10:06:00.581: D/gralloc_goldfish(560): Emulator without GPU emulation detected. 
06-04 10:06:00.781: W/TextLayoutCache(560): computeValuesWithHarfbuzz -- need to force to single run 
06-04 10:07:37.460: D/dalvikvm(560): GC_CONCURRENT freed 20K, 2% free 8923K/9095K, paused 10ms+53ms 
06-04 10:07:42.911: D/dalvikvm(560): GC_FOR_ALLOC freed 99K, 3% free 8965K/9223K, paused 72ms 
06-04 10:07:42.962: I/dalvikvm-heap(560): Grow heap (frag case) to 10.071MB for 1280016-byte allocation 
06-04 10:07:43.261: D/dalvikvm(560): GC_CONCURRENT freed 9K, 3% free 10205K/10503K, paused 45ms+8ms 
06-04 10:07:43.912: D/dalvikvm(560): GC_FOR_ALLOC freed 4K, 3% free 10377K/10631K, paused 93ms 
06-04 10:07:43.941: I/dalvikvm-heap(560): Grow heap (frag case) to 11.451MB for 1280016-byte allocation 
06-04 10:07:44.183: D/dalvikvm(560): GC_CONCURRENT freed <1K, 3% free 11626K/11911K, paused 8ms+9ms 
06-04 10:07:45.182: W/TextLayoutCache(560): computeValuesWithHarfbuzz -- need to force to single run 
06-04 10:07:48.961: D/AndroidRuntime(560): Shutting down VM 
06-04 10:07:48.961: W/dalvikvm(560): threadid=1: thread exiting with uncaught exception (group=0x409961f8) 
06-04 10:07:49.001: E/AndroidRuntime(560): FATAL EXCEPTION: main 
06-04 10:07:49.001: E/AndroidRuntime(560): java.lang.NullPointerException 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.app.Dialog.<init>(Dialog.java:149) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.app.Dialog.<init>(Dialog.java:127) 
06-04 10:07:49.001: E/AndroidRuntime(560): at com.astrixapp.Concejos$SectionFragmentCocina$1.onClick(Concejos.java:123) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.view.View.performClick(View.java:3480) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.view.View$PerformClick.run(View.java:13983) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.os.Handler.handleCallback(Handler.java:605) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.os.Handler.dispatchMessage(Handler.java:92) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.os.Looper.loop(Looper.java:137) 
06-04 10:07:49.001: E/AndroidRuntime(560): at android.app.ActivityThread.main(ActivityThread.java:4340) 
06-04 10:07:49.001: E/AndroidRuntime(560): at java.lang.reflect.Method.invokeNative(Native Method) 
06-04 10:07:49.001: E/AndroidRuntime(560): at java.lang.reflect.Method.invoke(Method.java:511) 
06-04 10:07:49.001: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
06-04 10:07:49.001: E/AndroidRuntime(560): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
06-04 10:07:49.001: E/AndroidRuntime(560): at dalvik.system.NativeStart.main(Native Method) 
06-04 10:07:53.230: I/Process(560): Sending signal. PID: 560 SIG: 9 

PD : 내가 말해 줘요 더 좋은 방법이 있다면, 내가 할 수있는 최선을 게시하려고 I 너의 도움을 apreciate, 그리고 내 영어로 미안 해요.

답변

1

컨텍스트 변수를 null로 설정 한 다음 해당 변수를 사용하여 AlertDialog을 만드는 것으로 보입니다. 그래서, 그것은 당신에게 NullPointerException를주고 있습니다.

Context context = null; 

시도는이 일을 :

Context context = SectionFragmentCocina.this.getActivity(); 
+0

ooohhhh 큰 일을 그 덕분에 많은 @android 학생 대신 일을 – speeder