java应用程序异常_应用程序启动时获取异常

我正在编写一个程序,在按下按钮时调用某人 . 但是,每当我启动应用程序时,它甚至会在按下按钮之前崩溃 . 这是代码:

package com.test;

import android.app.Activity;

import android.content.ActivityNotFoundException;

import android.os.Bundle;

import android.widget.*;

import android.view.*;

import android.view.View.OnClickListener;

import android.content.Intent;

import android.net.Uri;

import android.util.Log;

public class MainActivity extends Activity {

private OnClickListener mButtonListener = new OnClickListener() {

public void onClick(View v) {

try {

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:123456789"));

startActivity(callIntent);

}

catch (ActivityNotFoundException activityException) {

Log.e("Test", "Call failed");

}

}

};

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.button);

button.setOnClickListener(mButtonListener);

}

};

这是我的布局:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

这是我得到的错误(来自logcat)

D/AndroidRuntime( 337): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<

D/AndroidRuntime( 337): CheckJNI is ON

D/AndroidRuntime( 337): Calling main entry com.android.commands.am.Am

I/ActivityManager( 78): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.test/.MainActivity } from pid 337

I/ActivityManager( 78): Start proc com.test for activity com.test/.MainActivity: pid=345 uid=10035 gids={1015}

D/AndroidRuntime( 337): Shutting down VM

I/AndroidRuntime( 337): NOTE: attach of thread 'Binder Thread #3' failed

D/dalvikvm( 337): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 2ms+2ms

D/dalvikvm( 337): Debugger has detached; object registry had 1 entries

I/ARMAssembler( 78): generated scanline__00000177:03515104_00001002_00000000 [ 87 ipp] (110 ins) at [0x4456d6f0:0x4456d8a8] in 715314 ns

D/AndroidRuntime( 345): Shutting down VM

W/dalvikvm( 345): threadid=1: thread exiting with uncaught exception (group=0x40015560)

E/AndroidRuntime( 345): FATAL EXCEPTION: main

E/AndroidRuntime( 345): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.MainActivity}: java.lang.ClassCastException: android.widget.TextView

E/AndroidRuntime( 345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)

E/AndroidRuntime( 345): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)

E/AndroidRuntime( 345): at android.app.ActivityThread.access$1500(ActivityThread.java:117)

E/AndroidRuntime( 345): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

E/AndroidRuntime( 345): at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime( 345): at android.os.Looper.loop(Looper.java:123)

E/AndroidRuntime( 345): at android.app.ActivityThread.main(ActivityThread.java:3683)

E/AndroidRuntime( 345): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 345): at java.lang.reflect.Method.invoke(Method.java:507)

E/AndroidRuntime( 345): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

E/AndroidRuntime( 345): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

E/AndroidRuntime( 345): at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime( 345): Caused by: java.lang.ClassCastException: android.widget.TextView

E/AndroidRuntime( 345): at com.test.MainActivity.onCreate(MainActivity.java:34)

E/AndroidRuntime( 345): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

E/AndroidRuntime( 345): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

E/AndroidRuntime( 345): ... 11 more

W/ActivityManager( 78): Force finishing activity com.test/.MainActivity

W/ActivityManager( 78): Activity pause timeout for HistoryRecord{4059b300 com.test/.MainActivity}

W/ActivityManager( 78): Activity destroy timeout for HistoryRecord{4059b300 com.test/.MainActivity}

I/Process ( 345): Sending signal. PID: 345 SIG: 9

I/ActivityManager( 78): Process com.test (pid 345) has died.

W/InputManagerService( 78): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@405cdc18

提前致谢 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值