Android : Button not working. Keeps on forcing app close

on Friday, December 5, 2014


Whenever i insert my code (button) to a fragment, app forced close. I made an xml file with and i call it in fragment java but it has an adapter and in my xml i use framelayout to put the button at the most bottom of the page. I also try using footer but same error i got. anyone knows how to solve this one? thanks :)


XML FILE



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/takeQuiz"
android:orientation="horizontal"
android:background="@drawable/bg_linux_commands"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

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

<ListView android:id="@id/android:list"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginTop="125dp"/>

</LinearLayout>


<LinearLayout
android:layout_width="match_parent"
android:id="@+id/linearLayout"
android:layout_height="50dp"
android:gravity="center"
android:layout_gravity="bottom">

<Button
android:id="@+id/buttonTest"
android:layout_width="fill_parent
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/test" >
</Button>

</LinearLayout>
</FrameLayout>


FRAGMENT JAVA



public class LinuxCommands extends ListFragment{
String classes[] = { "File Managing System", "Scripting and Text Processing","Process and System Utility",
"System Information Commands","Archival and Comparison Commands","Command Shells"};

@SuppressLint("InflateParams")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// ActionBar
ActionBar mActionBar = getActivity().getActionBar();
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(getActivity());

View mCustomView = mInflater.inflate(R.layout.actionbar_ttg, null);
TextView mTextView = (TextView) mCustomView.findViewById(R.id.actionbar_ttg);
mTextView.setText("LINUX COMMANDS");
Typeface custom_font = Typeface.createFromAsset(getActivity().getAssets(),
"fonts/BRLNSR.TTF");
mTextView.setTypeface(custom_font);

mTextView.setTextSize(18);
mTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);

mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);

//Button
final Button button = (Button) getView().findViewById(R.id.buttonTest);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Quiz

Intent intent = new Intent (getActivity(), Terminal.class);
startActivity(intent);
}
});


ListAdapter adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,
classes);

// Setting the list adapter for the ListFragment
setListAdapter(adapter);
}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

return inflater.inflate(R.layout.fragment_linux_comm, container, false);

}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {


if(position == 0) {
Intent intent = new Intent (getActivity(), FileManagingSystemList.class);
startActivity(intent);
}
else if (position == 1){
Intent intent = new Intent (getActivity(),ScriptingAndTextProcessingList.class);
startActivity(intent);
}
else if (position == 2){
Intent intent = new Intent (getActivity(),ProcessAndSystemUtilityList.class);
startActivity(intent);
}
else if (position == 3){
Intent intent = new Intent (getActivity(),SystemInformationCmdList.class);
startActivity(intent);
}
else if (position == 4){
Intent intent = new Intent (getActivity(),ArchivalAndCompressionCmdList.class);
startActivity(intent);
}
else{
Intent intent = new Intent (getActivity(),CommandShellsList.class);
startActivity(intent);
}


}

}


LOGCAT



12-06 11:50:54.069: E/AndroidRuntime(26672): FATAL EXCEPTION: main
12-06 11:50:54.069: E/AndroidRuntime(26672): java.lang.NullPointerException
12-06 11:50:54.069: E/AndroidRuntime(26672): at com.example.ttg.fragment.LinuxCommands.onCreate(LinuxCommands.java:56)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.app.BackStackRecord.run(BackStackRecord.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.app.FragmentManagerImpl$1.run(FragmentManager.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.os.Handler.handleCallback(Handler.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.os.Handler.dispatchMessage(Handler.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.os.Looper.loop(Looper.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at android.app.ActivityThread.main(ActivityThread.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at java.lang.reflect.Method.invokeNative(Native Method)
12-06 11:50:54.069: E/AndroidRuntime(26672): at java.lang.reflect.Method.invoke(Method.java:511)
12-06 11:50:54.069: E/AndroidRuntime(26672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
12-06 11:50:54.069: E/AndroidRuntime(26672): at dalvik.system.NativeStart.main(Native Method)

0 comments:

Post a Comment