Das ist dieses Beispiel hier die ich modifizieren möchte:
Beiträge von F-Uraz
-
-
Irgendwo im Durcheinander der Logs mit der NullPointerException steht sicherlich, woher das Problem kommt.
Such mal da drin herum ob Du es findest.
Falls nicht, stell doch mal das komplette Log der Exception hier rein.Ich habe den Fehler nicht gefunden.. ich weiß nicht was ich falsch mache.. hm..
04-02 17:36:23.575: D/dalvikvm(806): GC_FOR_ALLOC freed 108K, 6% free 2911K/3080K, paused 48ms, total 51ms
04-02 17:36:23.876: D/libEGL(806): loaded /system/lib/egl/libEGL_emulation.so
04-02 17:36:23.886: D/(806): HostConnection::get() New Host Connection established 0x2a1f8388, tid 806
04-02 17:36:23.926: D/libEGL(806): loaded /system/lib/egl/libGLESv1_CM_emulation.so
04-02 17:36:23.946: D/libEGL(806): loaded /system/lib/egl/libGLESv2_emulation.so
04-02 17:36:24.126: W/EGL_emulation(806): eglSurfaceAttrib not implemented
04-02 17:36:24.146: D/OpenGLRenderer(806): Enabling debug mode 0
04-02 17:36:49.396: D/AndroidRuntime(806): Shutting down VM
04-02 17:36:49.396: W/dalvikvm(806): threadid=1: thread exiting with uncaught exception (group=0x41465700)
04-02 17:36:49.476: E/AndroidRuntime(806): FATAL EXCEPTION: main
04-02 17:36:49.476: E/AndroidRuntime(806): java.lang.NullPointerException
04-02 17:36:49.476: E/AndroidRuntime(806): at info.androidhive.tabsswipe.GamesFragment.onClick(GamesFragment.java:42)
04-02 17:36:49.476: E/AndroidRuntime(806): at android.view.View.performClick(View.java:4240)
04-02 17:36:49.476: E/AndroidRuntime(806): at android.view.View$PerformClick.run(View.java:17721)
04-02 17:36:49.476: E/AndroidRuntime(806): at android.os.Handler.handleCallback(Handler.java:730)
04-02 17:36:49.476: E/AndroidRuntime(806): at android.os.Handler.dispatchMessage(Handler.java:92)
04-02 17:36:49.476: E/AndroidRuntime(806): at android.os.Looper.loop(Looper.java:137)
04-02 17:36:49.476: E/AndroidRuntime(806): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-02 17:36:49.476: E/AndroidRuntime(806): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 17:36:49.476: E/AndroidRuntime(806): at java.lang.reflect.Method.invoke(Method.java:525)
04-02 17:36:49.476: E/AndroidRuntime(806): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-02 17:36:49.476: E/AndroidRuntime(806): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-02 17:36:49.476: E/AndroidRuntime(806): at dalvik.system.NativeStart.main(Native Method)
04-02 17:36:53.106: I/Process(806): Sending signal. PID: 806 SIG: 9 -
Hallo, ich habe ein Problem bei der Kommunikation zwischen den Fragmenten.
Beim Drücken eines Buttons im ersten Tab soll im zweiten Tab sich ein Text verändern aber das bekomme ich leider nicht hin. Der Compiler gibt mir den NullPointerException aus. Ich habe viel recherchiert aber nichts hilfreiches gefunden.Ich bin noch ein Anfänger und würde mich freuen, wenn mir jemand helfen kann
Codepackage info.androidhive.tabsswipe; public interface ActivityToMovies { public void activityConnection(boolean merkerMovies);}
Codepackage info.androidhive.tabsswipe; public interface GamesToActivity { public void connectionToActivity(boolean merker); }
Code
Alles anzeigenpackage info.androidhive.tabsswipe; import info.androidhive.tabsswipe.adapter.TabsPagerAdapter;import android.annotation.SuppressLint;import android.app.ActionBar;import android.app.ActionBar.Tab;import android.app.FragmentTransaction;import android.content.Intent;import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.support.v4.view.ViewPager; @SuppressLint("NewApi")public class MainActivity extends FragmentActivity implements ActionBar.TabListener,GamesToActivity { ActivityToMovies connection; public boolean merkerActivity; private ViewPager viewPager; private TabsPagerAdapter mAdapter; private ActionBar actionBar; // Tab titles private String[] tabs = { "Top Rated", "Games", "Movies" }; private String data = "Hallo es geht"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); actionBar = getActionBar(); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Adding Tabs for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name) .setTabListener(this)); } /** * on swiping the viewpager make respective tab selected * */ viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { // on tab selected // show respected fragment view viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { } @Override public void connectionToActivity(boolean merker) { // TODO Auto-generated method stub merker = this.merkerActivity; connection.activityConnection(merker); } }
Code
Alles anzeigenpackage info.androidhive.tabsswipe; import info.androidhive.tabsswipe.R;import android.content.Intent;import android.os.Bundle;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.widget.Button; public class GamesFragment extends Fragment implements OnClickListener{ public Button btn; GamesToActivity connection; public boolean merker = false; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_games, container, false); btn = (Button)rootView.findViewById(R.id.button1); btn.setOnClickListener(this); return rootView; } @Override public void onClick(View arg0) { // TODO Auto-generated method stub if(arg0.getId() == btn.getId()){ //set TEXT merker = true; connection.connectionToActivity(merker); } } }
Code
Alles anzeigenpackage info.androidhive.tabsswipe; import info.androidhive.tabsswipe.R;import android.R.bool;import android.os.Bundle;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.TextView; public class MoviesFragment extends Fragment implements ActivityToMovies { TextView txt; public boolean merker = false; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_movies, container, false); txt = (TextView)rootView.findViewById(R.id.textView1); if(merker == true){ txt.setText("Die Verbindung erfolgreich"); } else{ txt.setText("Keine Verbindung"); } return rootView; } @Override public void activityConnection(boolean merkerMovies) { // TODO Auto-generated method stub this.merker = merkerMovies; } }