1

こんにちは、アンドロイドプログラミング初心者です。作成しようとしているプログラムをコンパイルしているときに、実行時エラーが発生します。

ソースの添付ファイルには、Activity.class ファイルのソースが含まれていません

AnroidManifest.xml ファイルの内容は次のとおりです。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fragments"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

main.xml の内容は次のとおりです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
    android:name="com.example.fragments.Fragment1"
    android:id="@+id/fragment1"
    android:layout_weight="1"
    android:layout_width="0px"
    android:layout_height="match_parent" />

<fragment
    android:name="com.example.fragments.Fragment2"
    android:id="@+id/fragment2"
    android:layout_weight="1"
    android:layout_width="0px"
    android:layout_height="match_parent" />

MainActivity.java の内容は次のとおりです。

package com.example.fragments;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity 
{

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

}

これがfragment1.xmlの内容です

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00FF00" >

    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is fragment #1"
        android:textColor="#000000"
        android:textSize="25sp" />

</RelativeLayout>

Fragment1.java の内容は次のとおりです。

package com.example.fragments;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class Fragment1 extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.fragment1,container,false);
    }
}

これがfragment2.xmlの内容です

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFEE00" >

    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="This is fragment #2"
        android:textColor="#000000"
        android:textSize="25sp" />

</RelativeLayout>

Fragment2.java の内容は次のとおりです。

package com.example.fragments;

import android.annotation.TargetApi;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

@TargetApi(11)
public class Fragment2 extends Fragment
{
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.fragment2,container,false);
    }
}

事前にご協力いただきありがとうございます。

4

0 に答える 0