2016-12-10 7 views
0

私は単純なアプリケーションを作成しました。 私のアプリケーションの1つの画面には次のコードがあり、私はボタン(id "sendManual")を使用して、別のものにアプリケーションビューを変更します。 このコードの最後を見て、あなたはボタンのID "sendManual"を見ることができます。 私は、私は私のアンドロイド携帯電話にこのアプリをインストールしアプリを使用すると残念なことに "Intent intent = new ...."メソッドを使用すると画面が切り替わります

(私はこのコードを以下のコードApp2Activityのジャワを入れてきた、そして、あなたもそれを確認することができます)、それはApp2Activity.java

に画面表示を変更するためのセットアップを持っています私はボタンをクリックしたときにでも(ID "sendManual")アプリが突然停止し、言う

残念ながら、XXXXXアプリが停止した

public class showPermission implements View.OnClickListener { 

Dialog dialog; 
Activity activity; 
public void showDialog(final Activity activity){ 
    dialog = new Dialog(activity); 
    dialog.setCancelable(false); 
    this.activity=activity; 
    dialog.setTitle("XXXXX"); 
    dialog.setContentView(R.layout.permission); 
    Button Sendcancel = (Button) dialog.findViewById(R.id.sendCancel); 
    Button SendNow = (Button) dialog.findViewById(R.id.sendNow); 
    Button sendManual = (Button) dialog.findViewById(R.id.sendManual); 
    sendManual.setOnClickListener(this); 
    SendNow.setOnClickListener(this); 
    Sendcancel.setOnClickListener(this); 
    dialog.show(); 
} 


@Override 
public void onClick(View view) { 
    int id=view.getId(); 
    if(id==R.id.sendCancel){ 
     dialog.dismiss(); 
    } 
    else if(id==R.id.sendNow){ 
     sendSMS(); 

    } 
    else if(id==R.id.sendManual){ 
     Intent intent = new Intent(activity, App2Activity.class); 
    activity.startActivity(intent); 
    } 


} 
ここ

ここApp2Activity.java

public class App2Activity extends Activity { 

Button button; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main2); 

    findViewById(R.id.start).setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      sendSMS2(); 
     } 
    }); 
} 
............ etc 

のコードは、マニフェストファイルです。

<uses-permission android:name="android.permission.SEND_SMS"/> 

<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="16" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

+0

は、このリンクをチェックhttp://stackoverflow.com/questions/5152564/calling-one-activity-from-another-in- android –

+0

Manifest.xmlコードを追加できますか? –

+0

@ReadyAndroid投稿するには..を追加してください。 – Thunga

答えて

0

は、あなたが適切にIntent.Useにコンテキストを設定されていないこの

Intent intent = new Intent(getApplicationContext(), App2Activity.class); 
    startActivity(intent); 

代わり

Intent intent = new Intent(activity, App2Activity.class); 
activity.startActivity(intent); 
+0

showPermissionは単純なクラスで、アンドロイドのコンポーネントではないので、どのようにgetApplicationContext()を直接使用し、コンテキスト参照なしでstartActivityを使用することができますか? @tungaは活動参照で正しいことをしています。 –

+0

@サシクマールそれは私の上で動作しません – Thunga

0

のあなたがApp2Activityを宣言していなかったので、すべてが起こっている。このManifest.xml。マニフェストファイル内のすべてのアクティビティを宣言することは必須です。

この1とあなたのmanifest.xmlを置き換えます

<uses-sdk 
    android:minSdkVersion="14" 
    android:targetSdkVersion="16" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name=".App2Activity"/> 
</application> 
関連する問題