嘿同事们,
我需要一些帮助,试图找出我的Android应用程序中的Web浏览器崩溃的原因。任何帮助都会很棒。我将在连接到浏览器的受影响的JAVA类上发布我的代码,从技术上讲,它是一个包含不同类的相当大的程序。我还将包含android清单文件。所以我做的最后一次检查是我尝试用Jelly Bean下的平板电脑打开它,但它仍然崩溃。
这是webactivity类的代码
package com.example.gamaraza;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class WebActivity extends Activity {
private WebView webView;
@SuppressLint("SetJavaScriptEnabled")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.weblayout);
webView = (WebView) findViewById(R.id.buttonUrl);;
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.google.com");
}
}
Android Manifest将是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gamaraza"
android:versionCode="1"
android:versionName="1.0" >
<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
<screen android:screenSize="large" android:screenDensity="ldpi" />
<screen android:screenSize="large" android:screenDensity="mdpi" />
<screen android:screenSize="large" android:screenDensity="hdpi" />
<screen android:screenSize="large" android:screenDensity="xhdpi" />
<screen android:screenSize="xlarge" android:screenDensity="ldpi" />
<screen android:screenSize="xlarge" android:screenDensity="mdpi" />
<screen android:screenSize="xlarge" android:screenDensity="hdpi" />
<screen android:screenSize="xlarge" android:screenDensity="xhdpi" />
</compatible-screens>
<supports-screens android:resizeable="false"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
android:requiresSmallestWidthDp="240"
android:compatibleWidthLimitDp="240"
android:largestWidthLimitDp="320"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/glauncher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar" >
<activity
android:name="com.example.gamaraza.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:label="@string/app_name"
android:name="com.example.gamaraza.CreditActivity" >
</activity>
<activity
android:label="@string/app_name"
android:name="com.example.gamaraza.DubActivity" >
</activity>
<activity
android:label="@string/app_name"
android:name="com.example.gamaraza.AboutActivity" >
</activity>
<activity
android:label="@string/app_name"
android:name="com.example.gamaraza.SettingsActivity" >
</activity>
<activity
android:name=".WebViewActivity"
android:theme="@android:style/Theme.NoTitleBar" />
<activity
android:label="@string/app_name"
android:name=".WebBrowser" >
</activity>
</application>
</manifest>
提前谢谢
更新:
package com.example.gamaraza;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import com.example.gamaraza.R;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.Toast;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
class Mp3Filter implements FilenameFilter{
public boolean accept(File dir, String name){
return (name.endsWith(".mp3"));
}
}
public class DubActivity extends ListActivity {
Button buttonUrl;
ImageButton stopPlay, dub1, dub2, dub3, dub4, dub5, dub6, dub7, dub8, dub9, dub10, dub11, dub12, dub13, dub14, dub15, dub16;
Button recbtn, dubback, choosebtn;
private MediaPlayer do2n,do3n,do4n,do5n,do6n,do7n,do8n,do9n,do10n,do11n,do12n,do13n,do14n,do15n,do16n,do17n;
MediaPlayer mp, mediaPlayer, myPlayer;
MediaRecorder myRecorder, myRecorder2, myRecorder3, myRecorder4, myRecorder5;
private SeekBar seekBar;
private String outputFile = null;
ImageButton buttonPlayS;
private final Handler handler = new Handler();
private static final String SD_PATH = new String ("/sdcard/Music/");
private List<String> songs = new ArrayList<String>();
private MediaPlayer mpl = new MediaPlayer();
private String recholder = "not";
private String recorder = "one";
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyy_");
String strDate = sdf.format(c.getTime());
Calendar c2 = Calendar.getInstance();
SimpleDateFormat sdf2 = new SimpleDateFormat("HH-mm-ss");
String strDate2 = sdf2.format(c2.getTime());
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.dublayout);
outputFile = (SD_PATH) + "/gamaraza"+strDate+strDate2+".mp3";
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
myRecorder.setOutputFile(outputFile);
myRecorder2 = new MediaRecorder();
myRecorder2.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
myRecorder2.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
myRecorder2.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
myRecorder2.setOutputFile(outputFile);
myRecorder3 = new MediaRecorder();
myRecorder3.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
myRecorder3.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
myRecorder3.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
myRecorder3.setOutputFile(outputFile);
myRecorder4 = new MediaRecorder();
myRecorder4.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
myRecorder4.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
myRecorder4.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
myRecorder4.setOutputFile(outputFile);
myRecorder5 = new MediaRecorder();
myRecorder5.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
myRecorder5.setOutputFormat(MediaRecorder.OutputFormat.AMR_WB);
myRecorder5.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
myRecorder5.setOutputFile(outputFile);
addListenerButton();
longclick1();
choosebtn = (Button) this.findViewById(R.id.choosebtn);
choosebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ListView lv = getListView();
if(lv.isShown()){
lv.setVisibility(View.INVISIBLE);
mpl.reset();
songs.clear();
}else{
lv.setVisibility(View.VISIBLE);
longclick();
}
}});
final Button click =(Button)findViewById(R.id.buttonUrl);
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent launchactivity= new Intent(DubActivity.this,WebBrowser.class);
startActivity(launchactivity);
}
});
dub1 = (ImageButton) this.findViewById (R.id.dub1);
dub1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub1) {
do2n = MediaPlayer.create(DubActivity.this, R.raw.m1);
do2n.start();
do2n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub1) {
if (do2n != null) {
do2n.stop();
do2n.release();
do2n = null;
}
}
}
return true;
}
});
dub2 = (ImageButton) this.findViewById (R.id.dub2);
dub2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub2) {
do3n = MediaPlayer.create(DubActivity.this, R.raw.m2);
do3n.start();
do3n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub2) {
if (do3n != null) {
do3n.stop();
do3n.release();
do3n = null;
}
}
}
return true;
}
});
dub3 = (ImageButton) this.findViewById (R.id.dub3);
dub3.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub3) {
do4n = MediaPlayer.create(DubActivity.this, R.raw.m3);
do4n.start();
do4n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub3) {
if (do4n != null) {
do4n.stop();
do4n.release();
do4n = null;
}
}
}
return true;
}
});
dub4 = (ImageButton) this.findViewById (R.id.dub4);
dub4.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub4) {
do5n = MediaPlayer.create(DubActivity.this, R.raw.m4);
do5n.start();
do5n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub4) {
if (do5n != null) {
do5n.stop();
do5n.release();
do5n = null;
}
}
}
return true;
}
});
dub5 = (ImageButton) this.findViewById (R.id.dub5);
dub5.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub5) {
do6n = MediaPlayer.create(DubActivity.this, R.raw.m5);
do6n.start();
do6n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub5) {
if (do6n != null) {
do6n.stop();
do6n.release();
do6n = null;
}
}
}
return true;
}
});
dub6 = (ImageButton) this.findViewById (R.id.dub6);
dub6.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub6) {
do7n = MediaPlayer.create(DubActivity.this, R.raw.m6);
do7n.start();
do7n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub6) {
if (do7n != null) {
do7n.stop();
do7n.release();
do7n = null;
}
}
}
return true;
}
});
dub7 = (ImageButton) this.findViewById (R.id.dub7);
dub7.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub7) {
do8n = MediaPlayer.create(DubActivity.this, R.raw.m7);
do8n.start();
do8n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub7) {
if (do8n != null) {
do8n.stop();
do8n.release();
do8n = null;
}
}
}
return true;
}
});
dub8 = (ImageButton) this.findViewById (R.id.dub8);
dub8.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub8) {
do9n = MediaPlayer.create(DubActivity.this, R.raw.m8);
do9n.start();
do9n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub8) {
if (do9n != null) {
do9n.stop();
do9n.release();
do9n = null;
}
}
}
return true;
}
});
dub9 = (ImageButton) this.findViewById (R.id.dub9);
dub9.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub9) {
do10n = MediaPlayer.create(DubActivity.this, R.raw.m9);
do10n.start();
do10n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub9) {
if (do10n != null) {
do10n.stop();
do10n.release();
do10n = null;
}
}
}
return true;
}
});
dub10 = (ImageButton) this.findViewById (R.id.dub10);
dub10.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub10) {
do11n = MediaPlayer.create(DubActivity.this, R.raw.m10);
do11n.start();
do11n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub10) {
if (do11n != null) {
do11n.stop();
do11n.release();
do11n = null;
}
}
}
return true;
}
});
dub11 = (ImageButton) this.findViewById (R.id.dub11);
dub11.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub11) {
do12n = MediaPlayer.create(DubActivity.this, R.raw.m11);
do12n.start();
do12n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub11) {
if (do12n != null) {
do12n.stop();
do12n.release();
do12n = null;
}
}
}
return true;
}
});
dub12 = (ImageButton) this.findViewById (R.id.dub12);
dub12.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub12) {
do13n = MediaPlayer.create(DubActivity.this, R.raw.m12);
do13n.start();
do13n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub12) {
if (do13n != null) {
do13n.stop();
do13n.release();
do13n = null;
}
}
}
return true;
}
});
dub13 = (ImageButton) this.findViewById (R.id.dub13);
dub13.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub13) {
do14n = MediaPlayer.create(DubActivity.this, R.raw.m13);
do14n.start();
do14n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub13) {
if (do14n != null) {
do14n.stop();
do14n.release();
do14n = null;
}
}
}
return true;
}
});
dub14 = (ImageButton) this.findViewById (R.id.dub14);
dub14.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub14) {
do15n = MediaPlayer.create(DubActivity.this, R.raw.m14);
do15n.start();
do15n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub14) {
if (do15n != null) {
do15n.stop();
do15n.release();
do15n = null;
}
}
}
return true;
}
});
dub15 = (ImageButton) this.findViewById (R.id.dub15);
dub15.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub15) {
do16n = MediaPlayer.create(DubActivity.this, R.raw.m15);
do16n.start();
do16n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub15) {
if (do16n != null) {
do16n.stop();
do16n.release();
do16n = null;
}
}
}
return true;
}
});
dub16 = (ImageButton) this.findViewById (R.id.dub16);
dub16.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v.getId() == R.id.dub16) {
do17n = MediaPlayer.create(DubActivity.this, R.raw.m16);
do17n.start();
do17n.setLooping(true);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v.getId() == R.id.dub16) {
if (do17n != null) {
do17n.stop();
do17n.release();
do17n = null;
}
}
}
return true;
}
});
}
@Override
protected void onListItemClick(ListView list, View view, final int position, long id){
mpl.reset();
buttonPlayS = (ImageButton)findViewById(R.id.ButtonPlayStop);
buttonPlayS.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
if(mpl.isPlaying()) {
mpl.pause();
buttonPlayS.setBackgroundResource(R.drawable.playbtn);
}
else {
try {
mpl.setDataSource(SD_PATH + songs.get(position));
getListView().setVisibility(View.INVISIBLE);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
}
try {
mpl.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// TODO Auto-generated catch block
e.printStackTrace();
}
mpl.start();
seekBar = (SeekBar) findViewById(R.id.SeekBar01);
seekBar.setMax(mpl.getDuration());
seekBar.setProgress(mpl.getCurrentPosition());
startPlayProgressUpdater();
stopPlay = (ImageButton)findViewById(R.id.recstop);
stopPlay.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
mpl.stop();
seekBar.setProgress(0);
}
});
buttonPlayS.setBackgroundResource(R.drawable.playbtn2);
}
}
});
}
Dubactivity太大但您可以查看它的第一部分您将能够看到我在此活动中如何尝试进入Web浏览器选项