无法删除InvocationTargetException

时间:2012-04-30 10:24:50

标签: java android

我知道如果在不同的包中有两个具有相同名称的类,则抛出此异常。

但在这种情况下,我无法理解在遇到此语句时如何抛出此异常(如LogCat中所示)

s=tv2.getText().toString();其中s是String,ofcourse。

所以,请帮我解决问题。

这些是我使用的进口商品 -

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button; 
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

在期待中感谢你。

编辑:LogCat详细信息

04-30 15:46:53.373: D/dalvikvm(608): GC_EXTERNAL_ALLOC freed 26 objects / 816 bytes in 48ms
04-30 15:47:01.871: D/AndroidRuntime(608): Shutting down VM
04-30 15:47:01.871: W/dalvikvm(608): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-30 15:47:01.891: E/AndroidRuntime(608): FATAL EXCEPTION: main
04-30 15:47:01.891: E/AndroidRuntime(608): java.lang.IllegalStateException: Could not execute method of the activity
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.view.View$1.onClick(View.java:2072)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.view.View.performClick(View.java:2408)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.view.View$PerformClick.run(View.java:8816)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.os.Handler.handleCallback(Handler.java:587)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.os.Looper.loop(Looper.java:123)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.app.ActivityThread.main(ActivityThread.java:4627)
04-30 15:47:01.891: E/AndroidRuntime(608):  at java.lang.reflect.Method.invokeNative(Native Method)
04-30 15:47:01.891: E/AndroidRuntime(608):  at java.lang.reflect.Method.invoke(Method.java:521)
04-30 15:47:01.891: E/AndroidRuntime(608):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-30 15:47:01.891: E/AndroidRuntime(608):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-30 15:47:01.891: E/AndroidRuntime(608):  at dalvik.system.NativeStart.main(Native Method)
04-30 15:47:01.891: E/AndroidRuntime(608): Caused by: java.lang.reflect.InvocationTargetException
04-30 15:47:01.891: E/AndroidRuntime(608):  at yadav.sanjay.conv.ConvActivity.click(ConvActivity.java:392)
04-30 15:47:01.891: E/AndroidRuntime(608):  at java.lang.reflect.Method.invokeNative(Native Method)
04-30 15:47:01.891: E/AndroidRuntime(608):  at java.lang.reflect.Method.invoke(Method.java:521)
04-30 15:47:01.891: E/AndroidRuntime(608):  at android.view.View$1.onClick(View.java:2067)
04-30 15:47:01.891: E/AndroidRuntime(608):  ... 11 more
04-30 15:47:01.891: E/AndroidRuntime(608): Caused by: java.lang.NullPointerException
04-30 15:47:01.891: E/AndroidRuntime(608):  ... 15 more

很抱歉没有在之前发布logcat详细信息。

1 个答案:

答案 0 :(得分:1)

它不是InvocationTargetException,我认为它是由logcat中显示的NullPointerException引起的。这可能是因为tv2为null或tv2.getText()为null。请检查值为

if(tv2 != null)
 s=tv2.getText().toString();
else 
 s= "";