Java TextView导致应用程序崩溃
由于某种原因,当我调用TextView函数时,它会使我的应用程序崩溃。 我已经看过了与我类似的问题的答案,但我无法缩小我的问题范围 这是我第一次制作应用程序,也是我第一次使用Java。以前我只有C++/C方面的经验 从我的Android Manisfest文件Java TextView导致应用程序崩溃,java,android,eclipse,Java,Android,Eclipse,由于某种原因,当我调用TextView函数时,它会使我的应用程序崩溃。 我已经看过了与我类似的问题的答案,但我无法缩小我的问题范围 这是我第一次制作应用程序,也是我第一次使用Java。以前我只有C++/C方面的经验 从我的Android Manisfest文件 <activity android:name="sg.blogspot.ce9005project.LegalNoticesActivity" android:label="@string/actio
<activity
android:name="sg.blogspot.ce9005project.LegalNoticesActivity"
android:label="@string/action_legalnotices" >
</activity>
findViewById(R.id.textId)).setText(GooglePlayServicesUtil.getOpenSourceSoftware许可证信息(本))代码>是错误的
在使用TextView之前,您没有声明它
胡乱猜测:您有一个NullPointerException,对吗?
确保在/res/layout/activity\u legal\u notices.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textId"/>
package sg.blogspot.ce9005project;
import com.google.android.gms.common.GooglePlayServicesUtil;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class LegalNoticesActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_legal_notices);
//Original line below
((TextView)
findViewById(R.id.textId)).setText(GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this));
//The 2 lines below were modified by me but still do not work
//TextView textView = (TextView) findViewById(R.id.textId);
//textView.setText("TEST");
//The below line works. The problem, that means, lies with TextView
//Toast.makeText(this, GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(this),
Toast.LENGTH_SHORT).show();
}
}