Ben Fragment
içeride TextView
yanıp istiyorum ama bunun bir hata referans boş nesnesi benim kodudur veren oldu. Gerçekten burada çok
hatapublic class TwoFragment extends Fragment { View inflaterView; public TwoFragment() { // Required empty public constructor @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { inflaterView = inflater.inflate(R.layout.fragment_one, container, false); blink(); // Inflate the layout for this fragment return inflaterView; } private void blink() { final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() { int timeToBlink = 1000; //in milissegunds try { Thread.sleep(timeToBlink); } catch (Exception e) { } handler.post(new Runnable() { @Override public void run() { TextView txt = (TextView) inflaterView.findViewById(R.id.usage); if (txt.getVisibility() == inflaterView.VISIBLE) { txt.setVisibility(inflaterView.INVISIBLE); } else { txt.setVisibility(inflaterView.VISIBLE); } blink(); } }); } }).start(); } }
04-01 22:25:34.471 27846-27846/com.example.siluni.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.siluni.myapplication, PID: 27846
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.TextView.getVisibility()' on a null object reference
at com.example.siluni.myapplication.TwoFragment$1$1.run(TwoFragment.java:59)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5930)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Xml takdir herhangi biri yardımcı olabilir lütfen android için yeni
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<TextView
android:id="@+id/usage"
android:layout_marginTop="220dip"
android:layout_marginLeft="45dip"
android:layout_marginRight="15dip"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Google "
android:textColor="#030900"/>
Tüm hata iletisini gönderir misiniz? –
R.layout.fragment_one dosyasında id (@ + id/use) içeren bir TextView içeriyor muydunuz? –
yp bu pencereden bir metin görünümü var –