setContentView导致资源$ NotFoundException

时间:2016-04-21 15:10:39

标签: android eclipse android-activity

我现在尝试使用Eclipse制作的二手Android库。这个库包含一个Activity,但是当我从项目中调用自己这个窗口后,我收到了一个错误。

主要项目的主要活动:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final Button btStart = (Button) findViewById(R.id.btStart);
        btStart.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Context cnt  = getApplicationContext();
                Intent intent = new Intent(cnt,TestActivity.class);
                startActivity(intent);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                cnt.startActivity(intent);
            }
        });
    }
}

清单:

<application

    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="com.tagproduct.ultilib.TestActivity"
        android:theme="@android:style/Theme.Light"
        android:label="test">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>

错误:

04-21 17:03:33.639 29085-29085/com.tagproduct.dev.testlib E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.tagproduct.dev.testlib, PID: 29085
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tagproduct.dev.testlib/com.tagproduct.ultilib.TestActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030018
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
        at android.app.ActivityThread.access$800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5299)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030018
        at android.content.res.Resources.getValue(Resources.java:1133)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2365)
        at android.content.res.Resources.getLayout(Resources.java:949)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:305)
        at android.app.Activity.setContentView(Activity.java:1944)
        at com.tagproduct.ultilib.TestActivity.onCreate(TestActivity.java:15)
        at android.app.Activity.performCreate(Activity.java:5264)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
        at android.os.Handler.dispatchMessage(Handler.java:110) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:5299) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:515) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641) 
        at dalvik.system.NativeStart.main(Native Method) 

Styles.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.NoTitleBar">
    <item name="android:windowContentOverlay">@null</item>
</style>

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.tagproduct.dev.testlib.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <Button
        android:id="@+id/btStart"
        android:text="Start"
        android:layout_width="150dp"
        android:layout_height="75dp"
        android:layout_marginLeft="150dp"
        android:background="#880000FF" />

</RelativeLayout>

图书馆的活动:

public class TestActivity extends Activity {
TextView txView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.tagproduct.ultilib.R.layout.activity_test);
    txView = (TextView) findViewById(com.tagproduct.ultilib.R.id.txView);
    txView.setText("Chargement");
}

activity_test.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.tagproduct.ultilib.TestActivity" >

<TextView
    android:id="@+id/txView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

你能帮帮我吗?

谢谢

编辑:

我放弃了这个想法(不可能),我开始在内部做所有事情。

0 个答案:

没有答案