Android应用程序不断崩溃

Android应用程序不断崩溃,android,Android,当我打开我的android应用程序时,我总是会遇到一个错误 应用程序应用程序名称(process com.random.stuff)意外停止。 请再试一次 Logcat 04-04 05:51:39.975: D/AndroidRuntime(480): Shutting down VM 04-04 05:51:39.975: W/dalvikvm(480): threadid=1: thread exiting with uncaught exception (group=0x40015560

当我打开我的android应用程序时,我总是会遇到一个错误

应用程序应用程序名称(process com.random.stuff)意外停止。 请再试一次

Logcat

04-04 05:51:39.975: D/AndroidRuntime(480): Shutting down VM
04-04 05:51:39.975: W/dalvikvm(480): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-04 05:51:40.076: E/AndroidRuntime(480): FATAL EXCEPTION: main
04-04 05:51:40.076: E/AndroidRuntime(480): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thenewboston.joseph/com.random.stuff.StartingPoint}: java.lang.NullPointerException
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.os.Looper.loop(Looper.java:123)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-04 05:51:40.076: E/AndroidRuntime(480):  at java.lang.reflect.Method.invokeNative(Native Method)
04-04 05:51:40.076: E/AndroidRuntime(480):  at java.lang.reflect.Method.invoke(Method.java:507)
04-04 05:51:40.076: E/AndroidRuntime(480):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-04 05:51:40.076: E/AndroidRuntime(480):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-04 05:51:40.076: E/AndroidRuntime(480):  at dalvik.system.NativeStart.main(Native Method)
04-04 05:51:40.076: E/AndroidRuntime(480): Caused by: java.lang.NullPointerException
04-04 05:51:40.076: E/AndroidRuntime(480):  at com.random.stuff.StartingPoint.(StartingPoint.java:17)
04-04 05:51:40.076: E/AndroidRuntime(480):  at java.lang.Class.newInstanceImpl(Native Method)
04-04 05:51:40.076: E/AndroidRuntime(480):  at java.lang.Class.newInstance(Class.java:1409)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-04 05:51:40.076: E/AndroidRuntime(480):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
04-04 05:51:40.076: E/AndroidRuntime(480):  ... 11 more
起始点:

package com.thenewboston.joseph; import android.os.Bundle; import android.app.Activity; import android.text.Editable; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @SuppressWarnings("unused") public class StartingPoint extends Activity { Button bGuess; TextView points, hint, result; EditText guess; String dog = "Dog"; String guessDog = guess.toString(); int point = 0; boolean isDog = ((String) hintp).contains("Has four legs and fur"); boolean isFrog = ((String) hintp).contains("Has four legs and is slimy"); boolean wrong; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_starting_point); bGuess = (Button) findViewById(R.id.bGuess); points = (TextView) findViewById(R.id.tPoints); hint = (TextView) findViewById(R.id.tHint); result = (TextView) findViewById(R.id.tResult); guess = (EditText) findViewById(R.id.eGuess); bGuess.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub hint.setText("Has four legs and fur"); if (isDog) { if ("dog".equals(guess.getText().toString())) { wrong = false; hint.setText("Has four legs and is slimy"); } } else { wrong = true; } if (isFrog) { if ("frog".equals(guess.getText().toString())) { wrong = false; } } else { wrong = true; } if (wrong) { point--; result.setText("False try again"); points.setText("Points: " + point); }else{ point++; result.setText("Correct"); points.setText("Points: " + point); } } }); } } 包com.thenewboston.joseph; 导入android.os.Bundle; 导入android.app.Activity; 导入android.text.Editable; 导入android.view.view; 导入android.widget.Button; 导入android.widget.EditText; 导入android.widget.TextView; @抑制警告(“未使用”) 公共类启动点扩展活动{ 按钮按钮; 文本视图点、提示、结果; 编辑文本猜测; 字符串dog=“dog”; 字符串guessDog=guess.toString(); int点=0; 布尔值isDog=((字符串)hintp).contains(“有四条腿和毛发”); 布尔值isFrog=((字符串)hintp).contains(“有四条腿,而且很粘”); 布尔错误; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u起点); bGuess=(按钮)findViewById(R.id.bGuess); points=(TextView)findViewById(R.id.tPoints); 提示=(TextView)findViewById(R.id.tHint); 结果=(TextView)findViewById(R.id.tResult); guess=(EditText)findViewById(R.id.eGuess); bGuess.setOnClickListener(新视图.OnClickListener(){ @凌驾 公共void onClick(视图v){ //TODO自动生成的方法存根 hint.setText(“有四条腿和毛皮”); if(isDog){ if(“dog”.equals(guess.getText().toString())){ 错误=错误; hint.setText(“有四条腿,而且很粘”); } }否则{ 错=真; } if(isFrog){ if(“frog”.equals(guess.getText().toString())){ 错误=错误; } }否则{ 错=真; } 如果(错误){ 点--; result.setText(“False重试”); points.setText(“points:+point”); }否则{ point++; result.setText(“正确”); points.setText(“points:+point”); } } }); } } DDMS线路:

04-04 08:30:28.194: I/DEBUG(31): debuggerd: Feb  3 2011 14:45:34
04-04 08:30:28.225: D/qemud(38): entering main loop
04-04 08:30:28.244: I/Vold(29): Vold 2.1 (the revenge) firing up
04-04 08:30:28.264: I/Netd(30): Netd 1.0 starting
04-04 08:30:28.274: D/Vold(29): USB mass storage support is not enabled in the kernel
04-04 08:30:28.274: D/Vold(29): usb_configuration switch is not enabled in the kernel
04-04 08:30:28.274: D/Vold(29): Volume sdcard state changing -1 (Initializing) -> 0 (No-Media)
04-04 08:30:28.504: D/Vold(29): Volume sdcard state changing 0 (No-Media) -> 1 (Idle-Unmounted)
04-04 08:30:28.565: D/qemud(38): fdhandler_accept_event: accepting on fd 9
04-04 08:30:28.565: D/qemud(38): created client 0xe078 listening on fd 10
04-04 08:30:28.565: D/qemud(38): client_fd_receive: attempting registration for service 'boot-properties'
04-04 08:30:28.565: D/qemud(38): client_fd_receive:    -> received channel id 1
04-04 08:30:28.574: D/qemud(38): client_registration: registration succeeded for client 1
04-04 08:30:28.574: I/qemu-props(52): connected to 'boot-properties' qemud service.
04-04 08:30:28.574: I/qemu-props(52): receiving..
04-04 08:30:28.584: I/qemu-props(52): received: dalvik.vm.heapsize=32m
04-04 08:30:28.584: I/qemu-props(52): receiving..
04-04 08:30:28.584: I/qemu-props(52): received: qemu.sf.lcd_density=240
04-04 08:30:28.584: I/qemu-props(52): receiving..
04-04 08:30:28.584: I/qemu-props(52): received: qemu.hw.mainkeys=1
04-04 08:30:28.584: I/qemu-props(52): receiving..
04-04 08:30:28.584: I/qemu-props(52): received: qemu.sf.fake_camera=none
04-04 08:30:28.584: I/qemu-props(52): receiving..
04-04 08:30:28.584: I/qemu-props(52): exiting (4 properties set).
04-04 08:30:28.584: D/qemud(38): fdhandler_event: disconnect on fd 10
04-04 08:30:29.084: D/AndroidRuntime(33): >>>>>> AndroidRuntime START com.android.internal.os.ZygoteInit <<<<<<
04-04 08:30:29.084: D/AndroidRuntime(33): CheckJNI is ON
04-04 08:30:29.314: I/(34): ServiceManager: 0xad50


<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=".StartingPoint" >

 <Button
     android:id="@+id/bGuess"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentRight="true"
     android:text="Guess" />

  <TextView
     android:id="@+id/tPoints"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_alignRight="@+id/bGuess"
     android:text="Points: " />

 <TextView
    android:id="@+id/tResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/tHint"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="74dp"
    android:text="Result: "
    android:textAppearance="?android:attr/textAppearanceLarge" />

  <TextView
     android:id="@+id/tHint"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Hint: \n"
    android:textAppearance="?android:attr/textAppearanceLarge" />

 <EditText
    android:id="@+id/eGuess"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/bGuess"
    android:layout_alignLeft="@+id/bGuess"
    android:layout_alignRight="@+id/bGuess"
    android:ems="10" />

 </RelativeLayout>
04-04 08:30:28.194:I/DEBUG(31):debuggerd:Feb 3 2011 14:45:34
04-04 08:30:28.225:D/qemud(38):进入主回路
04-04 08:30:28.244:I/Vold(29):Vold 2.1(复仇)开火
04-04 08:30:28.264:I/Netd(30):Netd 1.0启动
04-04 08:30:28.274:D/Vold(29):内核中未启用USB大容量存储支持
04-04 08:30:28.274:D/Vold(29):内核中未启用usb_配置开关
04-04 08:30:28.274:D/Vold(29):卷SD卡状态更改-1(正在初始化)->0(无介质)
04-04 08:30:28.504:D/Vold(29):卷SD卡状态更改0(无介质)->1(空闲卸载)
04-04 08:30:28.565:D/qemud(38):fdhandler_accept_事件:在fd 9上接受
04-04 08:30:28.565:D/qemud(38):创建了在fd 10上侦听的客户端0xe078
04-04 08:30:28.565:D/qemud(38):客户端\u fd\u接收:正在尝试注册服务“启动属性”
04-04 08:30:28.565:D/qemud(38):客户端接收:->接收到的通道id 1
04-04 08:30:28.574:D/qemud(38):客户端注册:客户端1的注册成功
04-04 08:30:28.574:I/qemu道具(52):已连接到“启动属性”qemud服务。
04-04 08:30:28.574:I/qemu道具(52):接收。。
04-04 08:30:28.584:I/qemu道具(52):收到:dalvik.vm.heapsize=32m
04-04 08:30:28.584:I/qemu道具(52):接收。。
04-04 08:30:28.584:I/qemu道具(52):接收:qemu.sf.lcd_密度=240
04-04 08:30:28.584:I/qemu道具(52):接收。。
04-04 08:30:28.584:I/qemu道具(52):接收到:qemu.hw.mainkeys=1
04-04 08:30:28.584:I/qemu道具(52):接收。。
04-04 08:30:28.584:I/qemu道具(52):收到:qemu.sf.fake_camera=none
04-04 08:30:28.584:I/qemu道具(52):接收。。
04-04 08:30:28.584:I/qemu道具(52):退出(4个属性集)。
04-04 08:30:28.584:D/qemud(38):FDU事件:在fd 10上断开

04-04 08:30:29.084:D/AndroidRuntime(33):>>>>>>>AndroidRuntime开始com.android.internal.os.ZygoteInit您正面临
NullPointerExcetion
因为这一行
String guessDog=guess.toString()

只需将其替换为
stringguessdog

现在获取onClick()方法的文本,如下所示

public void onClick(View v) {
guessDog = guess.getText().toString();  // Add this line
.
. 
这是我这边的更新代码,我在init中做了一些更改

  • 我从.xml中删除了@dimon值,因为它不在我身边(您可以将它保存在代码中)
  • 我删除了这一行,而将直接值设为
    true
这是我的密码

@SuppressWarnings("unused")
public class StartingPoint extends Activity 
{

    Button bGuess;
    TextView points, hint, result;
    EditText guess;
    String dog = "Dog";
    String guessDog;
    int point = 0;

    boolean isDog = true;
    boolean isFrog = true;
    boolean wrong;

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

        bGuess = (Button) findViewById(R.id.bGuess);
        points = (TextView) findViewById(R.id.tPoints);
        hint = (TextView) findViewById(R.id.tHint);
        result = (TextView) findViewById(R.id.tResult);
        guess = (EditText) findViewById(R.id.eGuess);

        bGuess.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) 
            {
                guessDog = guess.toString();
                // TODO Auto-generated method stub

                hint.setText("Has four legs and fur");
                if (isDog) {

                    if ("dog".equals(guess.getText().toString())) {
                        wrong = false;
                        hint.setText("Has four legs and is slimy");
                    }
                } else {
                    wrong = true;
                }

                if (isFrog) {
                    if ("frog".equals(guess.getText().toString())) {
                        wrong = false;
                    }
                } else {
                    wrong = true;
                }

                if (wrong) {
                    point--;
                    result.setText("False try again");
                    points.setText("Points: " + point);
                }else{
                    point++;
                    result.setText("Correct");
                    points.setText("Points: " + point);
                }
            }
        });
    }
} 

请提供一些活动的代码。请上传活动的代码。您在
StartingPoint上有
NullPointerException
。java:17
,有一些东西被分配给
NULL
。检查一下,错误在Java代码的第17行,在com.random.stuff.StartingPoint。空指针异常也可能是引用错误的xml组件的结果。发布你的代码以获得更好的答案。很抱歉,我在尝试添加起始点代码时遇到了一个错误。它现在就在那里哦windows 7和我构建的计算机。虽然如此,我刚才也这么做了,我必须安装什么应用程序我必须在eclipse中安装一些东西,还是我只需按run as android applicationok,在您的设备上进行此设置,转到设置->应用程序->勾选“未知源”,然后有另一个名为“开发”的选项选择它并勾选“USB调试”。然后再次运行应用程序。如何获得设置