无法在Samsung Tab 3

时间:2015-08-08 04:59:56

标签: java android textview runtime-error settext

我的应用程序在打开Activiti时会出错。此错误只有三星Tab 3和其他设备运行稳定。亲爱的profissionaly请告知如何纠正错误。

代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView share=(TextView)findViewById(R.id.sharetext);
    share.setText("Share"); // error in this line :(
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<TextView
                    android:id="@+id/sharetext"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="20dp"
                    android:gravity="center"
                    android:text="Text"
                    android:textSize="14sp" />
</RelativeLayout>

logcat的:

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{tj.afkor.makon/tj.afkor.makon.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2404)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at tj.afkor.makon.MainActivity.onCreate(SourceFile:179)
at android.app.Activity.performCreate(Activity.java:5541)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
... 11 more

感谢任何建议

0 个答案:

没有答案