我正在尝试使用 android.support v4 jar 在 2.2/2.3 android 项目中实现片段,但它不断崩溃并给我这个错误:
06-07 14:23:43.774: E/AndroidRuntime(3085): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{mike.android.ie/mike.android.ie.ActivityView}: java.lang.ClassNotFoundException: mike.android.ie.ActivityView in loader dalvik.system.PathClassLoader[/data/app/mike.android.ie-1.apk]
我在代码中有其他片段,但已将其注释掉以尝试使一个片段正常工作,如果您能帮助我,我将不胜感激。
我正在使用的课程是:
活动视图.java
package mike.android.ie;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class ActivityView extends FragmentActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
和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"
android:orientation="vertical">
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="mike.android.ie.ImageViewFragment" android:layout_width="200dip"
android:layout_height="wrap_content" android:id="@+id/image_fragment"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
然后我有一个ImageViewFragment.java:
package mike.android.ie;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class ImageViewFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ImageView image = (ImageView) inflater.inflate(R.layout.imagefragment, container, false);
return image;
}
}
和imagefragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/myimage01" />
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ActivityView"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ImageViewFragment" android:screenOrientation="landscape"
android:configChanges="orientation" />
<activity android:name=".TickerFragment" android:screenOrientation="landscape"
android:configChanges="orientation" />
<activity android:name=".WebViewFragment" android:screenOrientation="landscape"
android:configChanges="orientation" />
<activity android:name=".VideoViewFragment" android:screenOrientation="landscape"
android:configChanges="orientation" />
</application>