Android Stepview库-尝试调用虚拟方法,Java空指针错误

Android Stepview库-尝试调用虚拟方法,Java空指针错误,android,performance,android-layout,listview,android-library,Android,Performance,Android Layout,Listview,Android Library,我在我的android应用程序中使用这个库,当我尝试使用开发人员提供的示例代码时,它运行良好,但他使用listview实现了它,有很多视图,我只需要在我的应用程序中使用一个,我绑定了添加它,但我不断遇到这个错误,请有人帮助我,android新手,我将非常感激 错误 activity_main.xml MainActivity.java package com.fayaz.uniabex; 导入android.content.Intent; 导入android.os.AsyncTask; 导入

我在我的android应用程序中使用这个库,当我尝试使用开发人员提供的示例代码时,它运行良好,但他使用listview实现了它,有很多视图,我只需要在我的应用程序中使用一个,我绑定了添加它,但我不断遇到这个错误,请有人帮助我,android新手,我将非常感激

错误

activity_main.xml


MainActivity.java

package com.fayaz.uniabex;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.support.design.widget.FloatingActionButton;
导入android.support.v7.app.AppActivity;
导入android.support.v7.widget.Toolbar;
导入android.util.Log;
导入android.view.view;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.widget.AdapterView;
导入android.widget.ListView;
导入android.widget.ProgressBar;
导入android.widget.Toast;
导入com.anton46.stepsview.stepsview;
导入com.google.firebase.database.ChildEventListener;
导入com.google.firebase.database.DataSnapshot;
导入com.google.firebase.database.DatabaseError;
导入com.google.firebase.database.DatabaseReference;
导入com.google.firebase.database.FirebaseDatabase;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.Map;
公共类MainActivity扩展了AppCompatActivity{
静态最终字符串标记=“主要活动”;
私有数据库参考数据库;
私人浮动按钮制造厂;
私人ProgressBar ProgressBar;
私有ListView项目;
私有静态MainActivity MainActivity;
私有静态ArrayList arrayListItem=新ArrayList();
私有项目详细信息适配器项目详细信息适配器;
私有数组列表密钥数组;
公共字符串recEmail=”uniabexappupdates@gmail.com";
公共字符串mailSubject=“”;
公共字符串mailBody=“”;
私有最终字符串[]标签={“询价”、“报价”、“采购订单”、“已发送”、“已接收”};
公共StepsView mStepsView;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
toolbar.setTitle(R.string.app_name);
设置支持操作栏(工具栏);
mDatabase=FirebaseDatabase.getInstance().getReference();
mDatabase.addChildEventListener(childEventListener);
主要活动=此;
progressBar=(progressBar)findViewById(R.id.progressBar);
fab=(FloatingActionButton)findViewById(R.id.fab);
lvItem=(ListView)findViewById(R.id.ItemList);
mStepsView=(StepsView)findviewbyd(R.id.StepsView);
keysArray=newarraylist();
lvItem.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
意向意向=新意向(MainActivity.this、ItemDetailsActivity.class);
意图。额外(“位置”,位置);
星触觉(意向);
}
});
fab.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
意向意向=新意向(MainActivity.this、AddOrUpdateItem.class);
意图。额外(“位置”,-1);
星触觉(意向);
}
});
itemDetailsAdapter=新的itemDetailsAdapter(MainActivity.this,arrayListItem);
lvItem.setAdapter(itemDetailsAdapter);
新建Wait().execute();
//台阶
getStep();
}
public void getStep(){
mStepsView.setLabels(标签)
.setBarColorIndicator(getApplicationContext().getResources().getColor(R.color.material\u blue\u grey\u 800))
.setProgressColorIndicator(getApplicationContext().getResources().getColor(R.color.orange))
.setLabelColorIndicator(getApplicationContext().getResources().getColor(R.color.orange))
.setCompletedPosition(2)
.drawView();
}
私有类等待扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
progressBar.setVisibility(View.VISIBLE);
lvItem.setVisibility(View.GONE);
}
@凌驾
受保护的布尔doInBackground(Void…params){
试一试{
睡眠(5000);
}
捕获(中断异常ie){
Log.d(TAG,即toString());
}
返回值(arrayListItem.size()=0);
}
@凌驾
受保护的void onPostExecute(布尔布尔布尔值){
如果(bool)
updateView();
}
}
公共静态MainActivity getInstance(){
返回主活动;
}
公共数组列表getKeysArray(){
返回键数组;
}
公共数据库引用getmDatabase(){
返回mDatabase;
}
公共无效附加项(项目模型){
项目=新项目();
setItem(model.getItem());
item.setPonum(model.getPonum());
item.setQty(model.getQty());
item.setSupplier(model.getSupplier());
item.setContact(model.getContact());
item.setTransporter(model.getTransporter());
item.setLrnum(model.getLrnum());
item.setComments(model.getComments());
String key=mDatabase.child(“Items”).push().getKey();
Map postValues=item.toMap();
Map childUpdates=newhashmap();
childUpdates.put(键、postValues);
mDatabase.updateChildren(childUpdates);
mailSubject=“New Item”+model.getItem().toString()+“已添加到材料应用程序。”;
mailBody=“Item:”+model.getItem().toString()+“\n”+
“PO:”+model.getPonum().toString()+“\n”+
数量:“+model.getQty().toString()+”\n”+
供应商:“+model.getSupplier().toString()+”\n”+
联系人:“+model.getContact().toString()+”\n”+
“Tran
Process: com.fayaz.uniabex, PID: 1056
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fayaz.uniabex/com.fayaz.uniabex.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.anton46.stepsview.StepsView com.anton46.stepsview.StepsView.setLabels(java.lang.String[])' on a null object reference
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
     at android.app.ActivityThread.-wrap12(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6077)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.anton46.stepsview.StepsView com.anton46.stepsview.StepsView.setLabels(java.lang.String[])' on a null object reference
     at com.fayaz.uniabex.MainActivity.getStep(MainActivity.java:99)
     at com.fayaz.uniabex.MainActivity.onCreate(MainActivity.java:95)
     at android.app.Activity.performCreate(Activity.java:6664)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
     at android.app.ActivityThread.-wrap12(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:154) 
     at android.app.ActivityThread.main(ActivityThread.java:6077) 
     at java.lang.reflect.Method.invoke(Native Method)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5dp"
    android:focusable="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="16dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/item"
                android:paddingTop="4dp"
                android:paddingRight="4dp"/>

            <TextView
                android:id="@+id/ItemNametv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Item : "
                android:textSize="20sp"
                android:layout_marginBottom="8dp"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/qty"
                android:paddingRight="4dp"/>

            <TextView
                android:id="@+id/qtytv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Qty : "
                android:layout_marginBottom="8dp"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <com.anton46.stepsview.StepsView
                android:id="@+id/stepsView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

        </LinearLayout>


        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="#c0c0c0"
            android:layout_marginBottom="8dp"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Button
                android:id="@+id/EditItem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Edit"
                android:minWidth="0dp"
                android:minHeight="0dp"
                style="@style/Widget.AppCompat.Button.Borderless"/>

            <Button
                android:id="@+id/DeleteItem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Delete"
                android:textColor="@color/btn_logut_bg"
                android:minWidth="0dp"
                android:minHeight="0dp"
                style="@style/Widget.AppCompat.Button.Borderless"/>

        </LinearLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

</LinearLayout>
package com.fayaz.uniabex;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.anton46.stepsview.StepsView;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

static final String TAG = "Main Activity";
private DatabaseReference mDatabase;
private FloatingActionButton fab;
private ProgressBar progressBar;
private ListView lvItem;
private static MainActivity mainActivity;
private static ArrayList<Item> arrayListItem = new ArrayList<>();
private ItemDetailsAdapter itemDetailsAdapter;
private ArrayList<String> keysArray;
public String recEmail = "uniabexappupdates@gmail.com";
public String mailSubject ="";
public String mailBody="";
private final String[] labels = {"Enquiry", "Quotation", "PO Rel", "Dispatched", "Received"};
public StepsView mStepsView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.app_name);
    setSupportActionBar(toolbar);



    mDatabase = FirebaseDatabase.getInstance().getReference();
    mDatabase.addChildEventListener(childEventListener);
    mainActivity = this;

    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    fab = (FloatingActionButton) findViewById(R.id.fab);
    lvItem = (ListView) findViewById(R.id.ItemList);
    mStepsView = (StepsView) findViewById(R.id.stepsView);



    keysArray = new ArrayList<>();

    lvItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(MainActivity.this, ItemDetailsActivity.class);
            intent.putExtra("Position", position);
            startActivity(intent);
        }
    });



    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(MainActivity.this, AddOrUpdateItem.class);
            intent.putExtra("Position", -1);
            startActivity(intent);
        }
    });

    itemDetailsAdapter = new ItemDetailsAdapter(MainActivity.this, arrayListItem);
    lvItem.setAdapter(itemDetailsAdapter);

    new Wait().execute();

    //Steps
    getStep();
}

public void getStep(){
    mStepsView.setLabels(labels)
            .setBarColorIndicator(getApplicationContext().getResources().getColor(R.color.material_blue_grey_800))
            .setProgressColorIndicator(getApplicationContext().getResources().getColor(R.color.orange))
            .setLabelColorIndicator(getApplicationContext().getResources().getColor(R.color.orange))
            .setCompletedPosition(2)
            .drawView();
}

private class Wait extends AsyncTask<Void, Void, Boolean> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        progressBar.setVisibility(View.VISIBLE);
        lvItem.setVisibility(View.GONE);
    }

    @Override
    protected Boolean doInBackground(Void... params) {
        try {
            Thread.sleep(5000);
        }
        catch (InterruptedException ie) {
            Log.d(TAG,ie.toString());
        }
        return(arrayListItem.size()==0);
    }

    @Override
    protected void onPostExecute(Boolean bool) {
        if(bool)
            updateView();
    }
}

public static MainActivity getInstance() {
    return mainActivity;
}

public ArrayList<String> getKeysArray() {
    return keysArray;
}

public DatabaseReference getmDatabase() {
    return mDatabase;
}

public void addItem(Item model) {
    Item item = new Item();
    item.setItem(model.getItem());
    item.setPonum(model.getPonum());
    item.setQty(model.getQty());
    item.setSupplier(model.getSupplier());
    item.setContact(model.getContact());
    item.setTransporter(model.getTransporter());
    item.setLrnum(model.getLrnum());
    item.setRemarks(model.getRemarks());

    String key = mDatabase.child("Items").push().getKey();
    Map<String, Object> postValues = item.toMap();

    Map<String, Object> childUpdates = new HashMap<>();
    childUpdates.put(key, postValues);
    mDatabase.updateChildren(childUpdates);

    mailSubject ="New Item " + model.getItem().toString() + " is added to Materials app.";
    mailBody = "Item : " + model.getItem().toString() + "\n" +
            "PO # : " + model.getPonum().toString() + "\n" +
            "Qty : " + model.getQty().toString() + "\n" +
            "Supplier : " + model.getSupplier().toString() + "\n" +
            "Contact : " + model.getContact().toString() + "\n" +
            "Transport : " + model.getTransporter().toString() + "\n" +
            "LR # : " + model.getLrnum().toString() + "\n" +
            "Remarks : " + model.getRemarks().toString();

    //Creating SendMail object
    SendMail sm = new SendMail(this, recEmail, mailSubject, mailBody);

    //Executing sendmail to send email
    sm.execute();

}

public void deleteItem(int position) {
    String clickedKey = keysArray.get(position);
    mDatabase.child(clickedKey).removeValue();
}

public void updateItemDetails(final Item model, int position) {
    String clickedKey = keysArray.get(position);
    Item item = new Item();
    item.setItem(model.getItem());
    item.setPonum(model.getPonum());
    item.setQty(model.getQty());
    item.setSupplier(model.getSupplier());
    item.setContact(model.getContact());
    item.setTransporter(model.getTransporter());
    item.setLrnum(model.getLrnum());
    item.setRemarks(model.getRemarks());
    mDatabase.child(clickedKey).setValue(item);

    mailSubject = "Item " + model.getItem().toString() + " is Updated to Materials app.";
    mailBody = "Item : " + model.getItem().toString() + "\n" +
            "PO # : " + model.getPonum().toString() + "\n" +
            "Qty : " + model.getQty().toString() + "\n" +
            "Supplier : " + model.getSupplier().toString() + "\n" +
            "Contact : " + model.getContact().toString() + "\n" +
            "Transport : " + model.getTransporter().toString() + "\n" +
            "LR # : " + model.getLrnum().toString() + "\n" +
            "Remarks : " + model.getRemarks().toString();

    //Creating SendMail object
    SendMail sm = new SendMail(this, recEmail, mailSubject, mailBody);

    //Executing sendmail to send email
    sm.execute();
}

ChildEventListener childEventListener = new ChildEventListener() {
    @Override
    public void onChildAdded(DataSnapshot dataSnapshot, String s) {
        lvItem.setVisibility(View.GONE);
        progressBar.setVisibility(View.VISIBLE);
        Log.d(TAG, dataSnapshot.getKey() + ":" + dataSnapshot.getValue().toString());
        Item item = dataSnapshot.getValue(Item.class);
        arrayListItem.add(item);
        keysArray.add(dataSnapshot.getKey());
        updateView();
    }
    @Override
    public void onChildChanged(DataSnapshot dataSnapshot, String s) {
        String changedKey = dataSnapshot.getKey();
        int changedIndex = keysArray.indexOf(changedKey);
        Item item = dataSnapshot.getValue(Item.class);
        arrayListItem.set(changedIndex,item);
        updateView();
    }
    @Override
    public void onChildRemoved(DataSnapshot dataSnapshot) {
        String deletedKey = dataSnapshot.getKey();
        int removedIndex = keysArray.indexOf(deletedKey);
        keysArray.remove(removedIndex);
        arrayListItem.remove(removedIndex);
        updateView();
    }
    @Override
    public void onChildMoved(DataSnapshot dataSnapshot, String s) { }
    @Override
    public void onCancelled(DatabaseError databaseError) {
        Toast.makeText(getApplicationContext(),"Could not update.",Toast.LENGTH_SHORT).show();
        updateView();
    }
};

@Override
protected void onDestroy() {
    super.onDestroy();
    arrayListItem.clear();
    mDatabase.removeEventListener(childEventListener);
}

public void updateView() {
    itemDetailsAdapter.notifyDataSetChanged();
    lvItem.invalidate();
    progressBar.setVisibility(View.GONE);
    lvItem.setVisibility(View.VISIBLE);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
        if (id == R.id.settings) {
            Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
        startActivity(intent);
        }
        return super.onOptionsItemSelected(item);
    }
}