开发者

Android Application crashing before running. Intent Problem or else?

Problem is simple. Two Activities. One throwing intent at other. Project have name : "Stupidroid" package : "com.examples.stupidroid" activity : "stupidOnSteroids"

below is stupidOnSteroids .java

package com.examples.stupidroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class stupidOnSteroids extends Activity {
    private Button buttonThatWillTakeYouPlacesButton;
    private Intent intentThatwillTakeYouPlacesIntent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        InitLayouts();
        InitSetOnClickListeners();
    }
    private void InitSetOnClickListeners() {
        buttonThatWillTakeYouPlacesButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                intentThatwillTakeYouPlacesIntent.setAction("");
            }
        });

    }
    private void InitLayouts() {
        buttonThatWillTakeYouPlacesButton = (Button)findViewById(R.id.buttonThatWillGiveThyPowerButton);

        intentThatwillTakeYouPlacesIntent = new Intent(stupidOnSteroids.this, Calc_print_codefile.class);

    }
}

now is main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="right"
    >
<Button android:id="@+id/goToOtherMoronButton"
    android:text="Next Activity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ></Button>
</LinearLayout>

now is another java file : Calc_print_codefile.java

package com.examples.stupidroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Calc_print_codefile extends Activity{
    Button buttonThatWillHelpYouCalculateButton;
    TextView textThatWillTakeTheHitText;
    Button buttonThatWillTakeYouHomeButton;
    Intent intentThatWillTakeYouHomeIntent;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calc_prin_layout);
        InitLayouts();
        InitSetOnClickListener();
    }
    private void InitSetOnClickListener() {
        buttonThatWillHelpYouCalculateButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                for(int i=0; i<32000; i++){
                    textThatWillTakeTheHitText.setText(i);
                }

            }
        });

    }
    private void InitLayouts() {
        buttonThatWillHelpYouCalculateButton = (Button)findViewById(R.id.buttonThatWillGiveThyPowerButton);
        textThatWillTakeTheHitText = (TextView)findViewById(R.id.textThatWillAbsolveThyText);
        intentThatWillTakeYouHomeIntent = new Intent(Calc_print_codefile.this, stupidOnSteroids.class);

    }
}

corresponding xml : calc_prin_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView  android:id="@+id/textThatWillAbsolveThyText"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text=" "
    />
    <Button android:id="@+id/buttonThatWillGiveThyPowerButton"
        android:text="Press ME, hard!"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"></Button>
</LinearLayout>

below is AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.examples.stupidroid"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".stupidOnSteroids"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    <activity android:name="Calc_print_codefile"></activity>
</application>
    <uses-sdk android:minSdkVersion="8" />

</manifest> 

Here are images (actually one only):

Android Application crashing before running. Intent Problem or else?

now is information from DDMS

07-29 14:13:31.344: WARN/ActivityThread(379): Application com.examples.stupidroid is waiting for the debugger on port 8100...
07-29 14:13:31.374: INFO/System.out(379): Sending WAIT chunk
07-29 14:13:31.434: INFO/dalvikvm(379): Debugger is active
07-29 14:13:31.594: INFO/System.out(379): Debugger has connected
07-29 14:13:31.604: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:31.804: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:31.824: DEBUG/dalvikvm(33): GC_EXPLICIT freed 2 objects / 64 bytes in 556ms
07-29 14:13:32.038: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.296: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.444: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{440534a8 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:13:32.494: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.694: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:32.894: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.113: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.356: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.574: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:33.795: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.008: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.215: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.423: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.634: INFO/System.out(379): waiting for debugger to settle...
07-29 14:13:34.868: INFO/System.out(379): debugger has settled (1504)
07-29 14:13:40.587: WARN/ActivityManager(60): Launch timeout has expired, giving up wake lock!
07-29 14:13:41.254: WARN/ActivityManager(60): Activity idle timeout for HistoryRecord{44078b28 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:13:46.454: DEBUG/dalvikvm(135): GC_EXPLICIT freed 1190 objects / 62584 bytes in 179ms
07-29 14:13:57.363: DEBUG/dalvikvm(60): GC_FOR_MALLOC freed 12320 objects / 698248 bytes in 153ms
07-29 14:13:58.423: DEBUG/AndroidRuntime(379): Shutting down VM
07-29 14:13:58.423: WARN/dalvikvm(379): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
**07-29 14:13:58.543: ERROR/AndroidRuntime(379): FATAL EXCEPTION: main
07-29 14:13:58.543: ERROR/AndroidRuntime(379): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.stupidroid/com.examples.stupidroid.stupidOnSteroids}: java.lang.NullPointerException**
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.os.Looper.loop(Looper.java:123)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at java.lang.reflect.Method.invokeNative(Native Method)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at java.lang.reflect.Method.invoke(Method.java:521)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at dalvik.system.NativeStart.main(Native Method)
07-29 14:13:58.543: ERROR/AndroidRuntime(379): Caused by: java.lang.NullPointerException
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at com.examples.stupidroid.stupidOnSteroids.InitSetOnClickListeners(stupidOnSteroids.java:20)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at com.examples.stupidroid.stupidOnSteroids.onCreate(stupidOnSteroids.java:17)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:开发者_如何学编程1047)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-29 14:13:58.543: ERROR/AndroidRuntime(379):     ... 11 more
07-29 14:13:58.613: WARN/ActivityManager(60):   Force finishing activity com.examples.stupidroid/.stupidOnSteroids
07-29 14:13:59.128: WARN/ActivityManager(60): Activity pause timeout for HistoryRecord{44078b28 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:14:09.273: WARN/ActivityManager(60): Activity destroy timeout for HistoryRecord{44078b28 com.examples.stupidroid/.stupidOnSteroids}
07-29 14:14:13.443: INFO/Process(379): Sending signal. PID: 379 SIG: 9
07-29 14:14:13.465: INFO/ActivityManager(60): Process com.examples.stupidroid (pid 379) has died.
07-29 14:14:13.483: WARN/InputManagerService(60): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@43ef9a68

Please tell me what can I do? I have followed same approach the other guy followed. My other project is working. what can it be? is it wrong nomenclature or what? From my past experiences, it looks like very small very narrow mistake , might be silly, still can't put my finger at it. Thanks for spending time reading this.

And oh, if I remove InitSetOnClickListeners(); from stupidOnSteroids.java file, I can at least see a button. So, there might be error.


You initializing of your button is wrong. In your main xml you don't have a button with the id R.id.buttonThatWillGiveThyPowerButton. You should change it to R.id.goToOtherMoronButton.

You should take the time you spend to create this question to read the stacktrace (it says where to find the null pointer) and than spend the rest of the time to debug (if it is more complex than the simple null pointer). But a plus point for the quality of your question. Everything is there... code, log, pictures :)


Change:

 textThatWillTakeTheHitText.setText(i);

to:

textThatWillTakeTheHitText.setText(String.valueOf(i));


Make sure that this line:

buttonThatWillTakeYouPlacesButton = (Button)findViewById(R.id.buttonThatWillGiveThyPowerButton);

Actually returns something and not just null.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜