एंड्रॉइड स्टूडियो के लिए नया उत्पादन कर सकता है, और मैंने सोचा कि मैं ठीक कर रहा था, लेकिन कल रात एक त्रुटि में भाग गया कि मैं अपने सभी अच्छे प्रयासों के बावजूद ठीक नहीं लग रहा हूं। मेरी गतिविधियों में से एक बटन 'java.lang.NullPointerException' उत्पन्न कर सकता है, सिवाय इसके कि यह हर बार धक्का देने में विफल रहता है। यह गलत जगह आदि में कोड की एक पंक्ति को ऑर्डर करने के समान सरल हो सकता है, लेकिन मैं एंड्रॉइड स्टूडियो में इतना नया हूं, मुझे नहीं पता कि मैं कहां गलत हूं।बटन नल पॉइंटर अपवाद (एंड्रॉइड स्टूडियो)
public class searchPage extends AppCompatActivity {
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_page);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Button goBackButton = (Button) findViewById(R.id.goBackButton);
goBackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(searchPage.this, MainActivity.class));
}
});
यहाँ एक्सएमएल
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/goBackButton"
android:layout_marginTop="88dp"
android:layout_below="@+id/spinner4"
android:layout_centerHorizontal="true"
/>
और मैनिफ़ेस्ट फ़ाइल
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.onein.mobilefinalapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".searchPage"
android:label="@string/title_activity_search_page"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MoviePage"
android:label="@string/title_activity_movie_page"
android:theme="@style/AppTheme.NoActionBar"></activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
यहाँ है activity_search_page.xml
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_search_page" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
है
यदि आपको किसी अन्य जानकारी की आवश्यकता है, तो कृपया मुझे बताएं।
किसी भी मदद की बहुत सराहना की! धन्यवाद।
संपादित करें - डुप्लिकेट बटन हटा दिया, और activity_search_page.xml
कारण है कि आप एक ही आईडी 'goBackButton' के साथ दो बटन है? –
अपवाद स्टैक ट्रेस उपयोगी होगा। –
साझा करें गतिविधि_search_page.xml भी –