vendredi 17 juin 2016

TextView printing False

Picture of the Error

I'm new to Android and Java so please bear with me but this my code and right when I open my application the TextView returns false (even before I enter anything into my EditText boxes).

Any suggestions would be helpful, as I couldn't find anything online.

Java

package me.finalproject.com.apchemchemolyapp;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;


public class stoich_fragment extends Fragment
{
    View rootview;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.stoich_layout, container, false);
    return view;

}
public void getReactants()
{
    EditText r = (EditText) getView().findViewById(R.id.reactants);
    String reactant = r.toString();
    int i = 0;
    int j = 0;
    int k = 0;
    int l = 0;
    int[] arr = new int[j];
    String[] elements = new String[k];
    boolean isRunning = true;
    String s = "";
    while(isRunning == true)
    {
        String element = "";
        String let = reactant.substring(i, i+1);
        if(let.compareTo(let.toLowerCase()) > 0)
        {
            element += let;
            i++;
        }
        else if(let.compareTo(let.toLowerCase()) == 0)
        {
            element += let;
            i++;
        }
        else if (let.equals("0")||let.equals("1")||let.equals("2")||let.equals("3")||let.equals("4")||let.equals("5")||let.equals("6")||let.equals("7")||let.equals("8")||let.equals("9"))
        {
            int temp = Integer.parseInt(let);
            arr[l] = temp;
            elements[l] = element;
            l++;
            element = "";
        }
        else if(i == reactant.length()-1)
        {
            isRunning = false;
        }
    }
    // displays the elements isolated on the reactant side
    // to test to make sure my logic works
    for(int a = 0; a<reactant.length(); a++)
    {
        s += elements[a] + " : " + arr[a] + "n";
    }
    TextView beq = (TextView) getActivity().findViewById(R.id.balanced_equation);
    beq.setText(s);
    //String s declared in other portion of code
}

}

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/reactants"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="95dp" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/products"
    android:layout_alignBottom="@+id/reactants"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/beq"
    android:id="@+id/balanced_equation"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

Aucun commentaire:

Enregistrer un commentaire