2016-03-14 155 views
-1

首先,在MainActivity中,按下按鈕時,我創建一個新的意圖並調用它。然後,在第二個意圖中,我創建了一個新的意圖,並在另一個按鈕被按下時調用它。我可以從MainActivity調用意圖,但無法從第二個活動調用新創建的意圖。無法從MainActivity中的其他活動調用活動

另外,我爲AndroidManifest.xml中的所有意圖創建了條目。

誤差來如下:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asad.reflect/com.example.asad.reflect.Superclass}: java.lang.NullPointerException 

MainActivity.java

public void onClick(View v) 
    { 
     if(v.getId()==R.id.b1) 
     { 
      Intent i=new Intent(this,Callinterface.class); 
      startActivity(i); 
     } 
     else 
     { 
      Intent i=new Intent(this,Callclass.class); 
      startActivity(i); 
     } 
} 

Callclass.java

public void onClick(View v) { 
     et=(EditText)findViewById(R.id.textclass); 
     className=et.getText().toString(); 
     Intent i=new Intent(this,Superclass.class); 
     startActivity(i); 
    } 

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.asad.reflect"> 

    <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=".Callclass" 
      android:label="Callclass" 
      android:theme="@style/AppTheme.NoActionBar"> 
    </activity> 
     <activity 
      android:name=".Callinterface" 
      android:label="Callinterface" 
      android:theme="@style/AppTheme.NoActionBar"></activity> 
     <activity 
      android:name=".Superclass" 
      android:label="Superclass" 
      android:theme="@style/AppTheme.NoActionBar"></activity> 


     <!-- ATTENTION: This was auto-generated to add Google Play services to your project for 
      App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 
+1

錯誤是在超類的活動......我們展示相關的代碼有PLS –

+0

現在,它的工作fine.I在做一些錯誤,而充氣列表視圖。 – a874

回答

0

試着改變你的代碼

else if(v.getId() == R.id.button2){ 
    //Run your button 2 Intent 
}else if(v.getId() == R.id.button3){ 
    //Run Button 3 Intent 
} 
+0

問題是NullPointerException。我不認爲這解決了這個問題。 –

+0

好,然後嘗試重建項目,清理它,並確保您的按鈕引用是正確的。如果其他按鈕使用相同的代碼,那麼這個應該沒有什麼不同 – Ethan

+0

這不是「我的」項目。我只是一個過路人,告訴你你的答案並不能解決問題。 –