Picture of the ErrorTextView的打印假
我是新來的Android和Java,所以請多多包涵,但這個我的代碼和權當我打開我的應用程序TextView
回報false
(甚至在我輸入任何東西進入我的EditText
框) 。
任何建議將是有幫助的,因爲我在網上找不到任何東西。
的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" />
你需要更加描述你正在做什麼,以及它是如何失敗的。 「TextView返回false」實際上沒有多少意義。 –
你的意思是空「的TextView返回false」?我最好的猜測是你沒有得到「getview()」的預期觀點。 –
對不起,我添加了一個圖片鏈接,顯示我的意思是 – vdopp