import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.actionbarsherlock.app.SherlockFragment;
public class Fragment_1 extends SherlockFragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_1,
container, false);
ImageView button = (ImageView) view.findViewById(R.id.imageView1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(), Temp.class);
getActivity().startActivity(intent);
}
});
return view;
}
}
我正试图从片段活动转移到正常活动,但它显示活动页面,即写在上面的你好世界,但突然它不幸停止了。你能帮我么。我试图让它从过去的 3 天开始工作,但无法弄清楚到底是什么问题。即使我检查了数千次 android manifest 文件 .ie
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.paul"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.project.paul.Splash"
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="com.project.paul.Login"
android:theme="@android:style/Theme.Light.NoTitleBar" >
</activity>
<activity
android:name="com.project.paul.Option"
android:label="@string/title_activity_option"
android:theme="@style/Theme.Actionstyle" >
</activity>
<activity
android:name="com.project.paul.Fragment_1"
android:label="@string/title_activity_option"
android:theme="@style/Theme.Actionstyle" >
</activity>
<activity
android:name="com.project.paul.Fragment_2"
android:label="@string/title_activity_option"
android:theme="@style/Theme.Actionstyle" >
</activity>
<activity android:name="com.project.paul.ImageOptions"
>
</activity>
<activity
android:name="com.project.paul.Temp"
android:label="@string/title_activity_temp"
>
</activity>
</application>
</manifest>
如果您能帮我解决我的问题,我将不胜感激。
logcat 错误:
06-29 22:26:43.647:E/AndroidRuntime(773):致命异常:主要 06-29 22:26:43.647:E/AndroidRuntime(773):java.lang.NullPointerException 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.support.v4.app .FragmentManagerImpl.saveAllState(FragmentManager.java:1617) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481) 06-29 22 :26:43.647: E/AndroidRuntime(773): 在 android.app.Activity.performSaveInstanceState(Activity.java:1147) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.app.Instrumentation。 callActivityOnSaveInstanceState(Instrumentation.java:1216) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.app。ActivityThread.performStopActivityInner(ActivityThread.java:3129) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.app.ActivityThread.handleStopActivity(ActivityThread.java:3188) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.app.ActivityThread.access$900(ActivityThread.java:141) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.app.ActivityThread$H.handleMessage( ActivityThread.java:1261) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.os.Handler.dispatchMessage(Handler.java:99) 06-29 22:26:43.647: E/AndroidRuntime( 773): 在 android.os.Looper.loop(Looper.java:137) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 android.app.ActivityThread.main(ActivityThread.java:5041) 06 -29 22:26:43.647: E/AndroidRuntime(773): 在 java.lang.reflect.Method.invokeNative(Native Method) 06-29 22:26:43.647: E/AndroidRuntime(773): 在 java.lang。reflect.Method.invoke(Method.java:511) 06-29 22:26:43.647: E/AndroidRuntime(773): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06 -29 22:26:43.647: E/AndroidRuntime(773): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-29 22:26:43.647: E/AndroidRuntime(773):在 dalvik.system.NativeStart.main(Native Method) 06-29 22:26:48.096: E/Trace(793): 打开跟踪文件时出错:没有这样的文件或目录 (2)打开跟踪文件时出错:没有这样的文件或目录 (2)打开跟踪文件时出错:没有这样的文件或目录 (2)