无法从MainActivity中的其他活动调用活动

无法从MainActivity中的其他活动调用活动

问题描述:

首先,在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

试着改变你的代码

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

这不是“我的”项目。我只是一个过路人,告诉你你的答案并不能解决问题。 –