android app兼容性

时间:2012-08-17 17:42:08

标签: android android-fragments compatibility

我已经创建了一个目标api为4.0.3(15)的应用程序但我在清单中设置了min api是2.3.3(10)当我在我的4.0设备上运行应用程序时它可以找到,当我在我的2.3设备上运行它不会加载只是在启动时强制关闭...

我知道android在构建之间存在碎片问题,我想知道是否有一种简单的方法可以使应用程序在两个系统上运行,或者我是否必须编写2.3版本的代码。我是新手编码器,所以请温柔地对待我。

08-17 18:57:15.722: D/AndroidRuntime(4535): Shutting down VM
08-17 18:57:15.722: W/dalvikvm(4535): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
08-17 18:57:15.722: E/AndroidRuntime(4535): FATAL EXCEPTION: main
08-17 18:57:15.722: E/AndroidRuntime(4535): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.reading.festival/com.reading.festival.ReadingFestival2012Activity}: java.lang.ClassNotFoundException: com.reading.festival.ReadingFestival2012Activity in loader dalvik.system.PathClassLoader[/data/app/com.reading.festival-1.apk]
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.ActivityThread.access$1500(ActivityThread.java:135)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.os.Looper.loop(Looper.java:150)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.ActivityThread.main(ActivityThread.java:4385)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at java.lang.reflect.Method.invoke(Method.java:507)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at dalvik.system.NativeStart.main(Native Method)
08-17 18:57:15.722: E/AndroidRuntime(4535): Caused by: java.lang.ClassNotFoundException: com.reading.festival.ReadingFestival2012Activity in loader dalvik.system.PathClassLoader[/data/app/com.reading.festival-1.apk]
08-17 18:57:15.722: E/AndroidRuntime(4535):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
08-17 18:57:15.722: E/AndroidRuntime(4535):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1777)
08-17 18:57:15.722: E/AndroidRuntime(4535):     ... 11 more

主要活动

package com.reading.festival;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class ReadingFestivalGuide2012Activity extends Activity  {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //makes full screen and takes away title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //

    setContentView(R.layout.main);

    Button sitemap = (Button) findViewById(R.id.sitemap);
    sitemap.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), sitemap.class);
            startActivityForResult(myIntent, 0);
        }
    });

    Button lineup = (Button) findViewById(R.id.lineup);
    lineup.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), lineup.class);
            startActivityForResult(myIntent, 0);
                }
            });
        }
    }

2 个答案:

答案 0 :(得分:1)

您需要检查logcat是否存在确切的错误。 您的错误可能是您正在使用2.3版本设备上没有的“更新”代码。 Logcat是必须的(跟踪异常并弄清楚应用程序有什么问题)但是通过将目标SDK更改为10并检查编译错误,可以轻松检查我提到的问题。

答案 1 :(得分:0)

在阅读完我的代码之后,我已经设法解决了我正在使用xml调用的东西,我现在发现它不支持在14以下的api中删除了它现在可以使用了