扩展锁定模式活动时发生错误

时间:2014-04-18 13:43:22

标签: android

在我的应用程序中,我想扩展LockPatternActivity库类:

https://code.google.com/p/android-lockpattern/

import com.haibison.android.lockpattern.LockPatternActivity;
import com.haibison.android.lockpattern.R;
import com.haibison.android.lockpattern.*;
public class ExtendPatternActivity extends LockPatternActivity{

}

使用lockpattern的类:

   public class PatternSetter extends Activity{


Context context = this;
final int REQ_CREATE_PATTERN = 1;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.pattern_setter);

     Settings.Security.setAutoSavePattern(this, true);

 Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN, null, this, ExtendPatternActivity.class);
     this.startActivityForResult(intent, REQ_CREATE_PATTERN);



}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQ_CREATE_PATTERN: {
        if (resultCode == RESULT_OK) {
            char[] pattern = data.getCharArrayExtra(
                    LockPatternActivity.EXTRA_PATTERN);
                    Intent intent = new Intent(context, MainTheftActivity.class);
                    context.startActivity(intent);


}

但是这个错误错误:

04-18 20:37:32.597: E/AndroidRuntime(14712): java.lang.RuntimeException: Unable to start  
activity ComponentInfo{com.tndev.theftahead/com.tndev.theftahead.ExtendPatternActivity}:  
android.view.InflateException: Binary XML file line #18: Error inflating class 
com.haibison.android.lockpattern.widget.LockPatternView_v14
....
04-18 20:37:32.597: E/AndroidRuntime(14712): Caused by:  
android.content.res.Resources$NotFoundException: Resource ID #0x0
04-18 20:37:32.597: E/AndroidRuntime(14712):    at  
android.content.res.Resources.getValue(Resources.java:1163)
04-18 20:37:32.597: E/AndroidRuntime(14712):    at   
android.content.res.Resources.getColor(Resources.java:845)
04-18 20:37:32.597: E/AndroidRuntime(14712):    at  
com.haibison.android.lockpattern.widget.LockPatternView.<init>(LockPatternView.java:405)
04-18 20:37:32.597: E/AndroidRuntime(14712):    at   
com.haibison.android.lockpattern.widget.LockPatternView_v14.<init>(LockPatternView_v14.java:42)

似乎ExtendPatternActivity无法正确加载lockpattern库中的资源? 我应该如何将库中的资源加载到我的应用程序中? 非常感谢..

3 个答案:

答案 0 :(得分:1)

首先,如果要使用资源文件,则应将库用作Android库项目。在eclipse中右键单击项目,在&#34; Android&#34;财产,设置&#34;是图书馆&#34;为真。

enter image description here

然后,在您的应用程序项目中,将库项目添加到引用。

enter image description here

答案 1 :(得分:1)

这些错误的原因是我忘了在android清单中为我的活动添加一些属性。 它应该是:

    <activity android:name="ExtendPatternActivity"
           android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
           android:screenOrientation="user"
            android:theme="@style/Alp.42447968.Theme.Dark" 
            >   

   </activity>

而不是:

    <activity android:name="ExtendPatternActivity">   

   </activity>

答案 2 :(得分:0)

只是告诉那些使用应用程序选项卡操纵他们的Android清单的人,你要小心。因为错误我指定了android:theme =“@ style / Alp.42447968.BaseTheme.Dark”,我得到了同样的大错误。所以复制这些行:

<activity android:name="ExtendPatternActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:screenOrientation="user"
android:theme="@style/Alp.42447968.Theme.Dark" 
>   
</activity>

原样。希望它有所帮助!