0

我正在尝试在 Eclipse 中(在 Windows 中)制作一个 android 游戏。当我在模拟器和手机上运行我的程序时,我不断收到 nulpointerexceptions 和 classcastexceptions。我有 2 个类(活动),每个类都有自己的 xml 布局。主要活动完美运行。但是,当我启动第二个活动时:

final Intent i = new Intent(this, Arrowscreen.class);
... 
startActivity(i);

我得到了前面提到的例外。它始终指向未找到的源。 无论如何在windows中通过eclipse中的源代码?我看过http://source.android.com,但似乎没有适用于 windows 的解决方案。我尝试按照 cygwin 的 linux 指令进行操作,但它似乎不起作用(如果可能的话,我更喜欢在 Windows 中工作)。

我还是 android 开发的新手,所以我可能会遗漏一些重要的东西。这个清单声明有什么问题吗?:

<activity android:name=".Arrowscreen" 
                android:screenOrientation="landscape"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                android:label="@string/app_name">
        <intent-filter>
                <action android:name="android.intent.action.RUN" />
                <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

我将避免发布我的整个代码示例,因为它很长,但我会告诉你它使用加速度计、gps 和一个可运行的用于带有“postDelayed”的计时器上的主循环。gps 精细定位权限也在清单中。我被卡住了,所以任何帮助将不胜感激。谢谢!

编辑:以下是我得到运行时异常的代码部分

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

        setContentView(R.layout.arrow);

        img=(ImageView)findViewById(R.id.ArrowBackground);
        arrow1=(ImageView)findViewById(R.id.turningArrow);
        GPSx=(TextView)findViewById(R.id.textView1);
        GPSy=(TextView)findViewById(R.id.textView2);
        MGNTx=(TextView)findViewById(R.id.textView3);
        MGNTy=(TextView)findViewById(R.id.textView4);
        angle = 0;
        lastAngle = 0;
        arrowAngle = 0;
        mValues[0]=0; mValues[1]=0; mValues[2]=0; 

        //mStartTime = System.currentTimeMillis();
        mHandler.removeCallbacks(UpdateArrow);
        mHandler.postDelayed(UpdateArrow, 400);
4

2 回答 2

1

除非我误解了你的问题...

在 Eclipse 中,在 Activity 的 onCreate 的第一行设置断点,并以调试模式启动应用程序(运行 -> 调试方式 -> Android 应用程序)。

关于这样做的两篇博客文章:1. http://www.droidnova.com/debugging-in-android-using-eclipse,541.html 2. http://www.latenightpc.com/blog/archives/2007/ 11/21/starting-a-debug-session-for-android-with-adt

于 2011-04-16T04:46:48.077 回答
0

看看你的“Arrowscreen”类是否扩展了“Activity”类,如果不是先这样做......

我认为这可能会有所帮助。

public class Arrowscreen extends Activity{

…………}

在 AndroidMainfest.xml

<activity android:name="Arrowscreen" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.RUN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

于 2011-04-16T04:55:27.300 回答