我尝试在Android模拟器上运行钛应用程序时出错

时间:2012-02-24 11:12:24

标签: android iphone titanium

我已经在钛工作室中构建了一个应用程序,我已经在iphone模拟器和iphone设备上运行它,它运行得很好。但是当我尝试在Android模拟器或Android设备上运行它时会崩溃。

我收到以下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartcrew/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: call to getView on a Window
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
at android.widget.TabHost.setCurrentTab(TabHost.java:323)
at android.widget.TabHost.addTab(TabHost.java:213)
at ti.modules.titanium.ui.widget.TiUITabGroup.addTab(TiUITabGroup.java:69)
at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:192)
at ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:275)
at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:91)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalStateException: call to getView on a Window
at ti.modules.titanium.ui.WindowProxy.getView(WindowProxy.java:63)
at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:384)
at ti.modules.titanium.ui.WindowProxy$1.windowCreated(WindowProxy.java:117)
at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:31)
at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:271)
at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:298)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

E/AndroidRuntime(  246): FATAL EXCEPTION: main
E/AndroidRuntime(  246): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartcrew/org.appcelerator.titanium.TiActivity}: java.lang.IllegalStateException: call to getView on a Window
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
at android.widget.TabHost.setCurrentTab(TabHost.java:323)
at android.widget.TabHost.addTab(TabHost.java:213)
at ti.modules.titanium.ui.widget.TiUITabGroup.addTab(TiUITabGroup.java:69)
at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:192)
at ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:275)
at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:91)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Caused by: java.lang.IllegalStateException: call to getView on a Window
at ti.modules.titanium.ui.WindowProxy.getView(WindowProxy.java:63)
at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:384)
at ti.modules.titanium.ui.WindowProxy$1.windowCreated(WindowProxy.java:117)
at org.appcelerator.titanium.TiActivityWindows.windowCreated(TiActivityWindows.java:31)
at org.appcelerator.titanium.TiBaseActivity.windowCreated(TiBaseActivity.java:271)
at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:298)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

有没有人知道什么是错的?我会发布一些代码,但是太长了,我不知道哪个部分会导致这个问题。

等待你的回答,谢谢!

1 个答案:

答案 0 :(得分:2)

// this sets the background color of the master UIView (when there are no windows/tab groups on it)


//Ti.include('Window1.js');
Titanium.UI.setBackgroundColor('#000');

// create tab group


var placeHolders = [{left:10, top:10, width:20, height:20, bgColor:"#FFF", bgAlpha:0.5, img:""},
                    {left:30, top:20, width:50, height:50, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""},
                    {left:60, top:60, width:20, height:20, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""},
                    {left:100, top:20, width:20, height:20, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""},
                    {left:50, top:100, width:20, height:20, bgColor:Math.random * 0xFFFFFF, bgAlpha:0.5, img:""}
                    ];


var tabGroup = Titanium.UI.createTabGroup();





var parentWindow = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundImage:"assets/background.png",
    backgroundColor:'#fff',
    navBarHidden:true,
    tabBarHidden:true
});
addPlaceHolders();

function addPlaceHolders()
{
    for(i = 0; i < placeHolders.length; i++)
    {
        var placeHolder = placeHolders[i];
        var placeHolderView = Titanium.UI.createView({
            top:placeHolder.top,
            left:placeHolder.left,
            height:placeHolder.height,
            width:placeHolder.width,
            backgroundColor:placeHolder.bgColor,
            opacity:placeHolder.bgAlpha

        });
        placeHolderView.name = i;
        parentWindow.add(placeHolderView);
        placeHolderView.addEventListener("click", onPlaceHolderClick);
    }
}


var main = Titanium.UI.createTab({  
    title:'Tab 1',
    window:parentWindow
});
//  add tabs
tabGroup.addTab(main);  

// open tab group
tabGroup.open();

function onPlaceHolderClick(e)
{
    //tell me wot to do here
    alert("tell me wo to do here");
}