[Отредактировано] Это XML-файл активности mainScreen, запрошенный некоторыми из вас
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:design="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F6F6F6">
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:fontFamily="@font/montserrat"
android:text="Pocket Budget"
android:textColor="#77dd77"
android:textSize="26dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView9"
android:layout_width="138dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:fontFamily="@font/montserrat"
android:gravity="center"
android:text="January"
android:textColor="#443c3c"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/textView8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView8"
app:layout_constraintTop_toTopOf="@+id/textView8" />
<View
android:id="@+id/view5"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginTop="7dp"
android:background="#FFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView8" />
<View
android:id="@+id/view2"
android:layout_width="116dp"
android:layout_height="50dp"
android:layout_marginBottom="3dp"
android:layout_marginEnd="3dp"
android:layout_marginTop="3dp"
android:background="#77dd77"
app:layout_constraintBottom_toBottomOf="@+id/view5"
app:layout_constraintEnd_toEndOf="@+id/view5"
app:layout_constraintTop_toTopOf="@+id/view5" />
<View
android:id="@+id/view3"
android:layout_width="116dp"
android:layout_height="50dp"
android:layout_marginBottom="3dp"
android:layout_marginStart="3dp"
android:layout_marginTop="3dp"
android:background="#779ecb"
app:layout_constraintBottom_toBottomOf="@+id/view5"
app:layout_constraintStart_toStartOf="@+id/view5"
app:layout_constraintTop_toTopOf="@+id/view5" />
<View
android:id="@+id/view4"
android:layout_width="116dp"
android:layout_height="50dp"
android:layout_marginBottom="3dp"
android:layout_marginEnd="3dp"
android:layout_marginStart="3dp"
android:layout_marginTop="3dp"
android:background="#ff6961"
app:layout_constraintBottom_toBottomOf="@+id/view5"
app:layout_constraintEnd_toStartOf="@+id/view2"
app:layout_constraintStart_toEndOf="@+id/view3"
app:layout_constraintTop_toTopOf="@+id/view5" />
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:fontFamily="@font/montserrat"
android:text="Balance"
android:textColor="#FFF"
android:textSize="9.5dp"
app:layout_constraintBaseline_toBaselineOf="@+id/textView2"
app:layout_constraintStart_toStartOf="@+id/view2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:fontFamily="@font/montserrat"
android:text="Expense"
android:textColor="#FFF"
android:textSize="9.5dp"
design:layout_constraintBaseline_toBaselineOf="@+id/textView"
design:layout_constraintStart_toStartOf="@+id/view4" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:fontFamily="@font/montserrat"
android:text="Income"
android:textColor="#FFF"
android:textSize="9.5dp"
design:layout_constraintStart_toStartOf="@+id/view3"
design:layout_constraintTop_toTopOf="@+id/view3" />
<TextView
android:id="@+id/textView4"
android:layout_width="116dp"
android:layout_height="25dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:autoSizeTextType="uniform"
android:fontFamily="@font/montserrat"
android:gravity="center"
android:text="₱ 0"
android:textColor="#FFF"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/textView6"
app:layout_constraintEnd_toEndOf="@+id/view3"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/view3"
app:layout_constraintTop_toTopOf="@+id/textView6"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:id="@+id/textView6"
android:layout_width="116dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:autoSizeTextType="uniform"
android:fontFamily="@font/montserrat"
android:gravity="center"
android:text="₱ 0"
android:textColor="#FFF"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/view4"
app:layout_constraintEnd_toEndOf="@+id/view4"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/view4"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView11"
android:layout_width="116dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="12dp"
android:layout_marginTop="8dp"
android:autoSizeTextType="uniform"
android:fontFamily="@font/montserrat"
android:gravity="center"
android:text="₱ 0"
android:textColor="#FFF"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/textView6"
app:layout_constraintEnd_toEndOf="@+id/view2"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/view2"
app:layout_constraintTop_toTopOf="@+id/textView6" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:fontFamily="@font/montserrat"
android:text="Transactions"
android:textColor="#808080"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view5" />
<ListView
android:id="@+id/transacList"
android:layout_width="344dp"
android:layout_height="438dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:background="#FFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:layout_constraintVertical_bias="0.0"></ListView>
</android.support.constraint.ConstraintLayout>
Это код моего пользовательского ListView. Я не знаю, что не так, потому что я новичок вandroid development
package com.example.admin.test2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import org.w3c.dom.Text;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Timer().schedule(new TimerTask(){
@Override
public void run(){
startActivity(new Intent(MainActivity.this, ScreenOne.class));
}
}, 2500);
mListView = (ListView) findViewById(R.id.transacList);
CustomAdaptor cAdaptor = new CustomAdaptor();
mListView.setAdapter(cAdaptor);
}
class CustomAdaptor extends BaseAdapter{
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = getLayoutInflater().inflate(R.layout.customlist, null);
ImageView mImageView = (ImageView) view.findViewById(R.id.imageView2);
TextView mTextView = (TextView) view.findViewById(R.id.textView2);
TextView mTextView2 = (TextView) view.findViewById(R.id.textView3);
mImageView.setImageResource(R.drawable.car);
mTextView.setText("Transportation");
mTextView2.setText("₱ 100");
return view;
}
}
}
И это код для моего пользовательского макета просмотра списка, который будет реализован на моем главном экране для просмотра значка изображения с меткой и количеством
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView2"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="19dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.015"
app:srcCompat="@mipmap/ic_launcher" />
<TextView
android:id="@+id/textView3"
android:layout_width="120dp"
android:layout_height="25dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:autoSizeTextType="uniform"
android:text="Label"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="@+id/imageView2"
app:layout_constraintStart_toEndOf="@+id/imageView2"
app:layout_constraintTop_toTopOf="@+id/imageView2"
app:layout_constraintVertical_bias="1.0" />
<TextView
android:layout_width="147dp"
android:layout_height="21dp"
android:layout_marginEnd="18dp"
android:layout_marginStart="8dp"
android:autoSizeTextType="uniform"
android:gravity="right"
android:text="Amount"
app:layout_constraintBottom_toBottomOf="@+id/textView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="@+id/textView3"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
Этоошибка, с которой я столкнулся.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.admin.test2, PID: 9518
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.test2/com.example.admin.test2.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at com.example.admin.test2.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
кто-то, пожалуйста, помогите решить эту проблему, приложение при запуске принудительно закрывается, и я не знаю, что не так.