任何人都知道为什么这段代码不起作用,在我尝试安装Google AdMob广告SDK之前工作正常,然后我每次尝试运行它时都会突然崩溃。
package co.miniz.RageToonViewer;
import java.io.FileReader;
import java.net.MalformedURLException;
import java.net.URL;
import org.w3c.dom.Text;
import co.miniz.RageToonViewer.R;
import co.miniz.RageToonViewer.ImageNumbers;
import co.miniz.RageToonViewer.NoRepeatRandom;
import co.miniz.RageToonViewer.Download;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
public class RageToonViewerActivity extends Activity {
FileReader reader;
URL url;
Download DL;
NoRepeatRandom randGen;
ImageNumbers noOfImages;
ImageView imView;
Gallery g;
Text text1;
Bitmap bmImg;
TextView tv;
AssetManager assetManager;
int random;
int prevRand = -10;
int noOfFiles ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
requestWindowFeature(Window.FEATURE_NO_TITLE);
assetManager = getAssets();
DL = new Download();
imView = (ImageView)findViewById(R.id.mainImage);
imView.setScaleType(ImageView.ScaleType.FIT_CENTER);
//----- Get Number OF Images -----
noOfImages = new ImageNumbers();
noOfFiles = noOfImages.GetNumber();
//----- Set Button and Text outPut for testing -----
Button button1main = (Button) findViewById(R.id.button1);
tv = (TextView)findViewById(R.id.text1);
tv.setText("Click above for a random RageToon!");
//----- Generate Random Number -----
randGen = new NoRepeatRandom(0, noOfFiles);
random = randGen.GetRandom();
//----- Set First Image -----
imView.setImageBitmap(GetImage());
//----- Set up Button Click Action -----
button1main.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv.setText("Click above for a random RageToon!" + noOfFiles);
noOfFiles = noOfImages.GetNumber();
imView.setImageBitmap(GetImage());
}
});
imView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv.setText("Click above for a random RageToon!" + noOfFiles);
noOfFiles = noOfImages.GetNumber();
imView.setImageBitmap(GetImage());
}
});
}
public Bitmap GetImage() {
random = randGen.GetRandom();
URL tempURL = null;
try {
tempURL = new URL("http://miniz.co/RageToonApp/Images/" + random + ".jpg");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
Bitmap TempImage = DL.getRemoteImage(tempURL, tv);
if (TempImage == null)
{
TempImage = GetImage();
}
return TempImage;
}
}
调试时我可以看到java.lang.RuntimeException:无法在LogCat视图中实例化活动ComponentInfo。
感谢您的帮助! 罗斯。
编辑:来自LogCat
07-17 01:35:14.680: WARN/dalvikvm(3540): threadid=3: thread exiting with uncaught exception (group=0x40023160)
07-17 01:35:14.680: ERROR/AndroidRuntime(3540): Uncaught handler: thread main exiting due to uncaught exception
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{co.miniz.RageToonViewer/co.miniz.RageToon.RageToonViewerActivity}: java.lang.ClassNotFoundException: co.miniz.RageToon.RageToonViewerActivity in loader dalvik.system.PathClassLoader@458a4278
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2424)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.os.Looper.loop(Looper.java:123)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.ActivityThread.main(ActivityThread.java:4370)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at java.lang.reflect.Method.invoke(Method.java:521)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at dalvik.system.NativeStart.main(Native Method)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): Caused by: java.lang.ClassNotFoundException: co.miniz.RageToon.RageToonViewerActivity in loader dalvik.system.PathClassLoader@458a4278
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
07-17 01:35:14.770: ERROR/AndroidRuntime(3540): ... 11 more
07-17 01:35:14.890: ERROR/SemcCheckin(3540): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump
07-17 01:35:14.900: WARN/ActivityManager(1146): Unable to start service Intent { act=com.sonyericsson.android.jcrashcatcher.action.BUGREPORT_AUTO cmp=com.sonyericsson.android.jcrashcatcher/.JCrashCatcherService (has extras) }: not found
07-17 01:35:15.000: INFO/Process(1146): Sending signal. PID: 3540 SIG: 3
07-17 01:35:15.000: INFO/dalvikvm(3540): threadid=7: reacting to signal 3
07-17 01:35:15.000: ERROR/dalvikvm(3540): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
07-17 01:35:15.060: ERROR/SemcCheckin(1681): Get Crash Level : java.io.FileNotFoundException: /data/semc-checkin/crashdump
07-17 01:35:15.170: DEBUG/dalvikvm(2189): GC freed 264 objects / 16000 bytes in 32ms
07-17 01:35:19.036: WARN/jdwp(3540): Debugger is telling the VM to exit with code=1
编辑:感谢您的回复,但修复路径名后代码仍无法正常工作。 我发现我现在在eclipse中创建的每个应用程序,当我尝试在手机上运行时,会使用任何连接到互联网的应用程序崩溃了吗? 当我使用代码时,它们也会崩溃:
requestWindowFeature(Window.FEATURE_NO_TITLE);
我希望这有助于确定出了什么问题。
答案 0 :(得分:3)
很明显,dalvik在路径“co.miniz.RageToon.RageToonViewerActivity”下查找文件“RageToonViewerActivity”,但是在包“package co.miniz.RageToonViewer中定义“因此无法找到。
我建议你去android清单文件和你定义活动的地方,给出完整的路径。
<activity android:name="co.miniz.RageToonViewer.RageToonViewerActivity" // change this line
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2.清理您的项目。并且去吧!!
Gud luck !!
答案 1 :(得分:0)
请注意以下描述:java.lang.ClassNotFoundException: co.miniz.RageToon.RageToonViewerActivity in loader dalvik.system.PathClassLoader
检查你的课程路径。
答案 2 :(得分:0)
我使用时遇到了同样的问题:requestWindowFeature(Window.FEATURE_NO_TITLE);
现在我使用下面的代码并且没有崩溃。
this.requestWindowFeature(Window.FEATURE_NO_TITLE);