我正在尝试使用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]
我在代码中有其他片段,但已经评论过它只是尝试让一个片段正常工作,如果你能帮助我,我会赞成它。
我正在使用的课程是:
ActivityView.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" />
的manifest.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>
答案 0 :(得分:0)
错误:mike.android.ie/mike.android.ie.ActivityView
看起来不像标准片段lib lib。你有没有其他的lib可以导致这个bug吗?
答案 1 :(得分:0)
在你的main.xml中:
<fragment class="mike.android.ie.ImageViewFragment"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:id="@+id/image_fragment"
android:layout_alignParentTop="true"
/>