I am using this library in my android app Android-StepsView, when I tried with the sample code provided by the developer, it works fine, but he has implemented it with a listview, with lots of views, I just need only one in my app, I tied to add it, but I keep getting this error, someone please help me out, new to android, I will be very grateful.
Error
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)
activity_main.xml
<?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>
MainActivity.java
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);
}
}