Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:20+00:00 2026-06-17T23:27:20+00:00

I am beginner in android programming. I want to learn Fragment in android and

  • 0

I am beginner in android programming. I want to learn Fragment in android and I write the simple program but when I want run this, the program has error! Why?

MainActivity.java:

public class MainActivity extends Activity {

Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btn=(Button)findViewById(R.id.btn1);
    btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent1=new     Intent(MainActivity.this,TestFragment.class);
            startActivity(intent1);
        }
    });
}
}

TestFragment.java:

public class TestFragment extends FragmentActivity{
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_for_btn1);

}
 }

ViewFragment.java:

public class ViewFragment extends Fragment{
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle   savedInstanceState){
    View v=inflater.inflate(R.layout.ui_for_fragment1, container, false);

    Button btnf1;
    btnf1=(Button)v.findViewById(R.id.btnf1);
    btnf1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getActivity(), "This is first fragment!!",  Toast.LENGTH_LONG).show();   
        }
    });
    return v;

}
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
    android:id="@+id/btn1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="CLICK ME FOR TEST FRAGMENT!"/>
</LinearLayout>

fragment_for_btn1.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Fragment
    android:id="@+id/fr1"
    android:name="com.example.fragmentexample.ViewFragment"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</LinearLayout> 

ui_for_fragment1.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <Button
    android:id="@+id/btnf1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CLICK:)"></Button>
 </LinearLayout>

LogCat is:

01-30 09:54:39.255: W/dalvikvm(14593): threadid=1: thread exiting with uncaught exception (group=0x4138e300)
01-30 09:54:39.270: E/AndroidRuntime(14593): FATAL EXCEPTION: main
01-30 09:54:39.270: E/AndroidRuntime(14593): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fragmentexample/com.example.fragmentexample.TestFragment}: android.view.InflateException: Binary XML file line #6: Error inflating class Fragment
01-30 09:54:39.270: E/AndroidRuntime(14593):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-30 09:54:39.270: E/AndroidRuntime(14593):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:27:21+00:00Added an answer on June 17, 2026 at 11:27 pm

    In your XML File fragment_for_btn1.xml:

    <Fragment
        android:id="@+id/fr1"
        android:name="om.example.fragmentexample.ViewFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    

    It should be

    <fragment
        android:id="@+id/fr1"
        class="com.example.fragmentexample.ViewFragment"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner in Android programming. I want to build a simple application
I'm a beginner in Android development but not in programming itself. Anyway, this question
I am a beginner in android programing. I want to write a program with
I am a beginner in Android programming and would want to display text entered
I am beginner in Android and want get Twitter trends, but getting a null
I'm beginner of Android. I want to run my first application on emulator. I
I want to learn Android client server communication programming. I don't like PHP much
As I am a beginner to Android programming, I was trying to run some
I'm a beginner android developer , I was trying to run this Linear Layout
I am a beginner programming android. I am searching for info how to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.