はオブジェクトを作成できません動作しないエラーがTab1をでTab1.java"表示"のフラグメントにバインドできません。 getViewメソッド():(
に含まれていると思いますが、タイマーが含まれていますが。したがって、私は、「レイアウト」を参照してくださいあなたを送った。
Tab.java
package com.android.example;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Tab1 extends Fragment {
private TextView tvDay, tvHour, tvMinute, tvSecond, tvEvent;
private LinearLayout linearLayout1, linearLayout2;
private Handler handler;
private Runnable runnable;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab_1, container, false);
initUI();
countDownStart();
return v;
}
@SuppressLint("SimpleDateFormat")
private void initUI() {
linearLayout1 = (LinearLayout) getView().findViewById(R.id.ll1);
linearLayout2 = (LinearLayout) getView().findViewById(R.id.ll2);
tvDay = (TextView) getView().findViewById(R.id.txtTimerDay);
tvHour = (TextView) getView().findViewById(R.id.txtTimerHour);
tvMinute = (TextView) getView().findViewById(R.id.txtTimerMinute);
tvSecond = (TextView) getView().findViewById(R.id.txtTimerSecond);
tvEvent = (TextView) getView().findViewById(R.id.tvevent);
}
// //////////////COUNT DOWN START/////////////////////////
public void countDownStart() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(this, 1000);
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
// Here Set your Event Date
Date futureDate = dateFormat.parse("2016-12-30");
Date currentDate = new Date();
if (!currentDate.after(futureDate)) {
long diff = futureDate.getTime()
- currentDate.getTime();
long days = diff/(24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
long hours = diff/(60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
long minutes = diff/(60 * 1000);
diff -= minutes * (60 * 1000);
long seconds = diff/1000;
tvDay.setText("" + String.format("%02d", days));
tvHour.setText("" + String.format("%02d", hours));
tvMinute.setText("" + String.format("%02d", minutes));
tvSecond.setText("" + String.format("%02d", seconds));
} else {
linearLayout1.setVisibility(View.VISIBLE);
linearLayout2.setVisibility(View.GONE);
tvEvent.setText("Android Event Start");
handler.removeCallbacks(runnable);
// handler.removeMessages(0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 0);
}
// //////////////COUNT DOWN END/////////////////////////
}
MainActivity.java はその後の断片に接続
それは、レイアウト<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" >
<LinearLayout
android:id="@+id/ll1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="@drawable/counter_back"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone" >
<TextView
android:id="@+id/tvevent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:singleLine="true"
android:text="Android Event Start"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:background="@drawable/counter_back"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/counter_back"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTimerDay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="@+id/txt_TimerDay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Days"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/counter_back"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTimerHour"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="@+id/txt_TimerHour"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Hour"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/counter_back"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTimerMinute"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="@+id/txt_TimerMinute"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Minute"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/counter_back"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTimerSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="center"
android:text="00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
<TextView
android:id="@+id/txt_TimerSecond"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Second"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
のGradleエラーです
tab_1.xml : 私は、エラーを把握することはできません。私は初心者プログラマ:)
03-19 18:00:55.154 28193-28193/? E/Zygote: v2
03-19 18:00:55.154 28193-28193/? I/libpersona: KNOX_SDCARD checking this for 10140
03-19 18:00:55.154 28193-28193/? I/libpersona: KNOX_SDCARD not a persona
03-19 18:00:55.154 28193-28193/? I/SELinux: Function: selinux_compare_spd_ram , priority [2] , priority version is VE=SEPF_SM-A300F_5.0.2-1_0026
03-19 18:00:55.154 28193-28193/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
03-19 18:00:55.154 28193-28193/? I/art: Late-enabling -Xcheck:jni
03-19 18:00:55.174 28193-28193/? D/TimaKeyStoreProvider: in addTimaSignatureService
03-19 18:00:55.184 28193-28193/? D/TimaKeyStoreProvider: Cannot add TimaSignature Service, License check Failed
03-19 18:00:55.184 28193-28193/? D/ActivityThread: Added TimaKesytore provider
03-19 18:00:55.374 28193-28193/com.android.example D/DisplayManager: DisplayManager()
03-19 18:00:55.714 28193-28240/com.android.example D/OpenGLRenderer: Render dirty regions requested: true
03-19 18:00:55.784 28193-28193/com.android.example W/FragmentManager: moveToState: Fragment state for Tab2{3edefe8b #0 id=0x7f0c0052} not updated inline; expected state 3 found 2
03-19 18:00:55.834 28193-28193/com.android.example D/AndroidRuntime: Shutting down VM
03-19 18:00:55.844 28193-28193/com.android.example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.example, PID: 28193
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at com.android.example.Tab1.initUI(Tab1.java:36)
at com.android.example.Tab1.onCreateView(Tab1.java:28)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:164)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)
at android.view.View.measure(View.java:17826)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17826)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:17826)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17826)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17826)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17826)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2748)
at android.view.View.measure(View.java:17826)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2030)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1174)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1395)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1062)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5873)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
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:5536)
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:1397)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.j
03-19 18:00:57.404 28193-28193/com.android.example I/Process: Sending signal. PID: 28193 SIG: 9
のViewGroupのV = inflater.inflate(Rを言及しています。 layout.tab_1、container、false); initUI(v)とinitUI(ViewGroup v)では、v.getViewById(R.id.name)のような処理を行います。 –