如何在android中的actionbarsherlock中使用简单按钮?

时间:2013-06-29 11:20:47

标签: java android actionbarsherlock

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;
     }



}

我正试图从片段活动转移到正常活动,但它显示活动页面,即写在其上的hello world但突然间它不幸地停止了。你能帮我么。我试图让它从过去的3天开始工作,但无法弄清楚究竟是什么问题。甚至我检查了几千次android清单文件.i.e。

<?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):at java.lang.reflect.Method.invokeNative(Native Method) 06-29 22:26:43.647:E / AndroidRuntime(773):at 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):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-29 22:26:43.647:E / AndroidRuntime(773):at dalvik.system.NativeStart.main(Native Method) 06-29 22:26:48.096:E / Trace(793):错误打开跟踪文件:没有这样的文件或目录(2)

1 个答案:

答案 0 :(得分:1)

看到这个帖子,它可能会有所帮助,如果没有,那么我会发布我的代码

NullPointerException on onSaveInstanceState with AndroidFragments